Get data from database and set it for a variable

I create my timeline like that scheduler.createTimelineView({ name: "timeline", x_unit: "day", x_date: "%d %F %Y", x_step: 1, x_size: 7, x_start: 1, x_length: 7, y_unit: rooms, y_property: "room_id", render: "bar", round_position: true, sort: timeframeSort });
with rooms var rooms = [ {key: "P01", label: "Phòng 1"}, {key: "P02", label: "Phòng 2"}, {key: "P03", label: "Phòng 3"}, {key: "P04", label: "Phòng 4"}, {key: "P05", label: "Phòng 5"}, {key: "P06", label: "Phòng 6"}, {key: "P07", label: "Phòng 7"}, {key: "P08", label: "Phòng 8"}, {key: "P09", label: "Phòng 9"}, {key: "P10", label: "Phòng 10"} ];
now i want rooms get data from database, i tried to use datastore [code]var rooms = new dhtmlXDataStore();
rooms.data.scheme({
$init:function(obj){
obj.key = obj.value;// ‘name’ is the name of the column from the db
obj.label = obj.label;
}
});

		var roomsdata = new dataProcessor("http://localhost/QLPTH/index.php/scheduler/rooms");
		roomsdata.init(rooms);[/code] with the value of [url]http://localhost/QLPTH/index.php/scheduler/rooms[/url] is [ {"value":"P01","label":"P01"}, {"value":"P02","label":"P02"} ] but it not work.

What can i do to get data from database and set it for my rooms variable?

I don’t know exactly how to do this but i’ve a trick for the same problem :
the rooms are generated by php like :

[code]var rooms = [

<?php $res=mysql_connect($db_server, $db_user, $db_password); mysql_select_db($db_database); $sql="select * from rooms"; $result=mysql_query($sql) or die('Error SQL !
'.$sql.'
'.mysql_error()); while ($room=mysql_fetch_assoc($result)) { echo "{key: '".$room["key"]."', label: '".$room["label"]."'}, echo "\n"; } ?>
     ];[/code]

It’s not the cleanest solution but that’s the only one i managed to get running.

If you are using connector for data generation - there is built in ability to load options for collections.

docs.dhtmlx.com/doku.php?id=dhtm … s_fetching

This approach can be used for sections in timiline as well.

The usage of datastore is overkill, but you can use it in similar way, define

y_unit:options:scheduler.serverList(“rooms”)},

and

roomsdata.attachEvent("onXLE", function(){ var room = scheduler.serverList("rooms") rooms.push.apply(rooms, this.serialize()); scheduler.callEvent("onOptionsLoad",[]); });

Thank for reply. I solved it