Insert Checked Row Values to table

Dear All,
I am new to dhtmlx. I spent about two days to find a solution for my problem. But failed. That’s why I am posting this question here.

I created a grid with data from two tables (students, subjects) which contains student_id as well as subject_id columns.
Then I added a check box column also.

What I need to do is create a button to insert student_ids and subject_ids of checked rows to another table ( subject_allocation).

In simple terms, i need to create new records in table subject_allocation for checked rows of the grid.

I really appreciate if anyone of you can show me the way of doing that.

It is always helpful for others if you explain your issue with help of code. For instance, what you have implemented so far, on what line of code you believe the problem is etc.

So far, the problem is understood, however it is not clear whether the rows after being checked are sent via dataprocessor call to the code which inserts records in subject_allocation table. What has been implemented so far?

For sending data from grid to the class/code, which inserts records in the table, is done via dataprocessor as shown below. I am using the below javascript function which is called when the user clicks Save button on my JSP page:-

function dataSave() {
 myDataProcessor.sendData();
 return true;
}

Now the way dataProcessor will know, which class to call in order to send the data from grid should be defined in your gridLoad method/function as below:-

function loadGrid(){
	mygrid = new dhtmlXGridObject('gridbox');
	mygrid.init();
	mygrid.loadXML(URL OF CLASS FOR LOADING THE GRID );
	myDataProcessor = new dataProcessor(URL OF CLASS TO WHICH GRID DATA WILL BE SENT);
	myDataProcessor.setTransactionMode("POST",true);
	myDataProcessor.setUpdateMode("on");
	myDataProcessor.init(mygrid);
}

I hope this helps.

-Sam

Dear Sam,
Thank you very much for the instructions and the support. I am using yii framework. This is what I did so far;

  1. Populate the ‘Student’ Grid and pass student_id
    View Code:
         <script type="text/javascript" charset="utf-8">
        mygrid = new dhtmlXGridObject('student');
        mygrid.setImagePath("../../../dhtmlx/grid/imgs/");
        mygrid.setSkin("dhx_skyblue");
        mygrid.setHeader("Name,Address");
       mygrid.attachEvent("onRowSelect", function(rID,cInd){
            mygrid2.clearAll();
            mygrid2.load("./grid_subject?id="+rID);
        })
        mygrid.loadXML("./grid_student");
        mygrid.init();             
        var mydp = new dataProcessor ("./grid_student");
        mydp.init(mygrid);
    </script>  
  1. Populate a grid containing student_id , subject_id and check boxes to select. This grid linked to the student grid. And the insert function as you suggested.

View code:

 <script type="text/javascript" charset="utf-8">
        mygrid2 = new dhtmlXGridObject('allocation');
        mygrid2.setImagePath("../../../dhtmlx/grid/imgs/");
        mygrid2.setSkin("dhx_skyblue");
        mygrid2.setHeader("Select,Student,Subject,Name");
        mygrid2.enableMultiselect(true);
        mygrid2.setColTypes("ch,ro,ro,ro");
        mygrid2.loadXML("./grid_subject");
        mygrid2.init();   
          
        myDataProcessor = new dataProcessor("./grid_allocation");
        myDataProcessor.setTransactionMode("POST",true);
        myDataProcessor.setUpdateMode("on");
        myDataProcessor.init(mygrid2);
       
        function allocate() {
            myDataProcessor.sendData();
            return true;
        } 
    </script>

Data processor for grid_subject:

    public function actionGrid_Subject() {
        include(dirname(__FILE__) . "/../../../dhtmlx/config.php");
        $res = mysql_connect("$host", "$user", "$password");
        mysql_select_db("$dbname");
        $id = mysql_real_escape_string($_GET['id']);
        $grid = new GridConnector($res, "MySQL");
        $grid->render_sql("select s1.id as student_id, s.id as subject_id,s.name as subject_name from ( select id,name from subject) as s
join (select id from student) as s1 where s1.id='" . $id . "'

", "", "'',student_id,subject_id,subject_name");
    }

Data processor for insert selected student_ids and subject_ids;

public function actionGrid_allocation() {
        include(dirname(__FILE__) . "/../../../dhtmlx/config.php");
        $res = mysql_connect("$host", "$user", "$password");
        mysql_select_db("$dbname");
        $grid = new GridConnector($res, "MySQL");
        $grid->render_table("subject_allocation", "id", "student_id,subject_id");
    }

Both student and subject grid are work well. When I checked the row with student_id=6 and subject_id = 1, and press allocate button ‘fire bug’ say it’s updated but my database was not updated.
Here are the fire bug outputs;
response

<?xml version='1.0' ?>

Post
1352414412x0_!nativeeditor_status=updated
1352414412x0_c0=1
1352414412x0_c1=6
1352414412x0_c2=1
1352414412x0_c3=Maths
1352414412x0_gr_id=1352414412x0
ids=1352414412x0

What I did wrong here? How can I make my database updated?
Thanks for your inputs and support.