Populating a select from database in DHX Scheduler

Hi,

Firstly, I’d like to say thank you for a great calendar/scheduler.

I’ve got the scheduler loading and saving events from mySql database. I’d like to populate a select in the lightbox with some names from my db. This is my client code:

function init() {
			scheduler.config.xml_date="%Y-%m-%d %H:%i";
			scheduler.config.first_hour = 8;
			scheduler.config.last_hour = 20;
			scheduler.config.details_on_create = true;
			scheduler.config.details_on_dblclick = true;
			scheduler.config.prevent_cache = true;

			scheduler.locale.labels.section_coach = "Coach:";
			scheduler.locale.labels.section_student = "Student:";	

			var sections = [
				{key:'coach1', label:'Coach 1'},
				{key:'coach2', label:'Coach 2'}
			];

			var students = [
				{key:'student1', label:'Student 1'},
				{key:'student2', label:'Student 2'}
			];
			
			scheduler.config.lightbox.sections = [
				{ name:"description", height:130, map_to:"text", type:"textarea" , focus:true },
				{ name:"student", height:72, type:"select", options:students, map_to:"student", filtering: true },
				{ name:"coach", height:43, type:"select", options:sections, map_to:"coach", filtering: true },
				{ name:"time", height:72, type:"time", map_to:"auto" }
			];

			scheduler.templates.event_class=function(start, end, event){
                if(event.coach) // if event has subject property then special class should be assigned
                    return "event_"+event.coach;

                return ""; // default return
            };

			scheduler.init('scheduler_here',null,"week");

			scheduler.load("data/connector.php");

			var dp = new dataProcessor("data/connector.php");
			dp.init(scheduler);

			var calendar = scheduler.renderCalendar({
				container:"cal_here", 
				navigation:true,
				handler:function(date){
					scheduler.setCurrentView(date, scheduler._mode);
				}
			});
			scheduler.linkCalendar(calendar);
			scheduler.setCurrentView(scheduler._date, scheduler._mode);
		}

This is my connector:

<?php 
require_once("../codebase/connector/scheduler_connector.php");
 
$res=mysql_connect("localhost","admin","admin");
mysql_select_db("vital_perch");
 
$conn = new SchedulerConnector($res);
$conn->enable_log("temp.log");
 
$conn->render_table("perch2_golf_bookings","booking_id","start_date,end_date,text,coach");
 
?>

I’m not great at javascript - can someone please tell me how to get my students options from the database instead of an array?

I’d like the first name and last name concatenated together in my select.

I really appreciate the help.

Jon

Is anyone able to help with this?

Can someone please help. I’m not sure whether to add the code from the examples to my existing connector.php (which is where my data is coming from) or whether to create a new one. I’ve looked through samples and the client code seems fairly easy but the instructions aren’t clear for the sever-side. I just need to populate a select in the lightbox in the scheduler with some names from a different table in my database. The events are being saved into a bookings table, but I need the names of the students to come from a students table.

Hello,
check ‘connector_options’ example from php connectors package:
connector-php/samples/scheduler/03_connector_options.php

Options can be loaded with the rest of data, and attached to the client with with ‘serverList’ api,
client:... scheduler.config.lightbox.sections = [ {name:"description", height:200, map_to:"text", type:"textarea" , focus:true}, {name:"type", height:21, map_to:"type", type:"select", options:scheduler.serverList("type")},//<--here it is {name:"time", height:72, type:"time", map_to:"auto"} ];server:[code] …
$res=mysql_connect($mysql_server,$mysql_user,$mysql_pass);
mysql_select_db($mysql_db);

$list = new OptionsConnector($res);
$list->render_table("types","typeid","typeid(value),name(label)");//'types'

$scheduler = new schedulerConnector($res);

//add options to the primary connector
$scheduler->set_options("type", $list);

$scheduler->render_table("tevents","event_id","start_date,end_date,event_name,type");[/code]

Thanks for your reply.

It’s this line I dont get:

$list->render_table("types","typeid","typeid(value),name(label)");//'types'

Say I have a table called ‘clients’ and I want to take the firstName from each of the rows and use that as the ‘type’ to list in the dropdown. How do I get it fom the database using your example?

It’s the typeid(value) and and name(value) that’s throwing me. Is this code added to my existing connector? DO I need to use the options_connector.php aswell as the scheduler connector?

I appreciate your patience.

Jon.

I’ve used the below code and it’s listing null as each of the select options:

require_once("../codebase/connector/scheduler_connector.php");
 
$res=mysql_connect("localhost","pass","pass");
mysql_select_db("db_name");

$list = new OptionsConnector($res);
$list->render_table("clients","clientId","firstName,lastName");//'types'

$conn = new SchedulerConnector($res);
$conn->enable_log("temp.log");

$conn->set_options("student", $list);
 
$conn->render_table("bookings","booking_id","start_date,end_date,text,coach,student");

I get the below in the log so it seems to be connecting ok.

====================================
Log started, 23/02/2013 04:49:51

SELECT booking_id,start_date,end_date,text,coach,student FROM bookings

SELECT clientId,firstName,lastName FROM clients

Done in 0.019742965698242s

It also seems to be getting the correct number of items from the database (7 in total) but each option is coming out as null.

How can i get it to output values rather than null?

Surely there’s someone here who can assist?

Jon.

Change

$list->render_table("clients","clientId","firstName,lastName");//'types'

as

$list->render_table("clients","clientId","firstName(value),lastName(label)");//'types'

And it will show something more meaningfull
As you need to show both fields as text, you may need to use more complex command, like

$list->render_sql("SELECT clientId, clientId as value, CONCAT (firstName, " ", lastName) as label FROM clients", "clientId", "value, label");