Passing a project ID during insert

How can I go about passing a project ID while inserting. I’m using dhtmlXscheduler. Updating works fine since updating doesn’t need the project ID. However when I insert, I don’t know how to pass my project ID.


[code]scheduler.config.xml_date=“%Y-%m-%d %H:%i”;
scheduler.init(‘scheduler_here’,new Date(),“month”);

	scheduler.locale.labels.section_teamleader="Team Leader";
		{name:"description", height:130, map_to:"text", type:"textarea" , focus:true},
		{name:"teamleader", height:23, type:"select", options:scheduler.serverList("team_leader"), map_to:"team_leader"},
		{name:"team", height:23, type:"multiselect", options:scheduler.serverList("team_leader"), map_to:"team"},
		{name:"time", height:72, type:"time", map_to:"auto"}

	var dp = new dataProcessor("calendar_data.php?project_id=<?=$_GET['project_id']?>");
	dp.setTransactionMode("POST", false);

Here’s the server code

[code]$scheduler = new schedulerConnector($db,“PDO”);

$list = new OptionsConnector($db, “PDO”);
$list->render_table(‘logins’,‘id’,‘id(value), first_name(label)’);

$scheduler->set_options(“team_leader”, $list);

$scheduler->render_sql("SELECT * FROM activities WHERE project_id = ". $_GET[‘project_id’], “id”, “date_start, date_end, subject, project_id”);[/code]

I’m not sure how to pass my project ID to the insert. Here is what the log says:

INSERT INTO activities(date_start,date_end,subject,project_id) VALUES ('2011-10-07 00:00','2011-10-07 00:05','test','')

Do I need to make a hidden field in the javascript or is there a way to do it in the connector?

What really makes no sense is if I add project_id to the render_sql like this:

SELECT * FROM activities WHERE project_id = ". $_GET[‘project_id’], “id”, "date_start, date_end, subject, project_id

It works for the update but not the insert

INSERT INTO activities(date_start,date_end,subject,project_id) VALUES (‘2011-10-20’,‘2011-10-20’,‘New event’,’’)

UPDATE activities SET date_start=‘2011-10-22’,date_end=‘2011-10-22’,subject=‘test2’,project_id=‘22492’ WHERE id=‘12434’ AND ( project_id = 22492)

You can use beforeInsert handler as

function custom_code($action){ $action->add_field("project_id", $_GET['project_id']); } $scheduler->event->attach("beforeInsert", custom_code);

Above code will force saving of project_id field during insert operation.

Looks like it works. Thanks.

Excellent, I needed a solution like that too. This should be made into a “how-to” :slight_smile:


I just used this technique for the event_id so that my app won’t use the auto-generated id, but it doesn’t work, any help guys?

Many thanks

In case of id - the situation is a bit more complicated, you will need to handle afterInsert as well, and from it call


to send correct id value back to client side.