Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Sandesh on Jan 20, 2010 22:59
open dhtmlx forum
dhtmlxScheduler: Updating two different tables in the DB(mysql)

Hi,

It would be great if someone help me to write a query on dhtmlxScheduler.


right now I am using below query to manage appointments,

    
$scheduler->render_sql("select * from appointments where user_id = ".$user_id, "event_id","start_date,end_date,event_name,email,user_id,mobile,description,reminder,sms_reminder,email_reminder");


!!!! ONLY appointments table records are shown in the scheduler.


but also I need another table should be updated/ inserted(with all same values of above! for eg. table name is appointment_test) if a new record/event is added using the last inserted ID of ABOVE query.

Can anyone help me to achieve this please.

Kind Regards,
Sandesh Kumar

Answer posted by Stanislav (support) on Jan 21, 2010 01:29
function doAfterProcessing($action){
   if ($action->get_status()=="inserted"){
       $id = $action->get_new_id();
       $start_date = $action->get_value("start_date"); 
       ... same for other fields ...
       mysql_query(...);
  }
}
$scheduler->event->attach("afterProcessing",doAfterProcessing);



http://dhtmlx.com/dhxdocs/doku.php?id=dhtmlxconnector:event_beforeupdate
Answer posted by Sandesh on Jan 21, 2010 03:58
Hi

Thanks for your reply.

I have added above code in the event.php file, but it didnt work.

i.e:

function default_values($action){
        global $user_id;
            
        $action->set_value("user_id",$user_id);
    }
    
    $scheduler->event->attach("beforeProcessing","default_values");
    
    $scheduler->render_sql("select * from appointments where user_id = ".$user_id, "event_id","start_date,end_date,event_name,email,user_id,mobile,description,reminder,sms_reminder,email_reminder");
    
          function doAfterProcessing($action){   //this is what I added
                if ($action->get_status()=="inserted"){
                       $id    = $action->get_new_id();
                       $email = $action->get_value("email"); 
        
                    $scheduler->sql->query("INSERT INTO appointments_test (email)
                            VALUES ('".$email."')");
                }
        }
        
$scheduler->event->attach("afterProcessing", doAfterProcessing);

Can you please guide me where to add your code please.

Kind regards,
Sandesh Kumar
Answer posted by Stanislav (support) on Jan 21, 2010 04:30
Change the order of command - all configuration need to be done before render command


$scheduler->event->attach("afterProcessing", doAfterProcessing);
 $scheduler->render_sql("select *...