How to Query SQL based on the selected item in a grid?

Hello,

Please help. I made a grid that take information from MySQL table. Based on the line number that will be selected in the grid I need to query another table in MySQL and populate the second grid.
Please advice what is the best way to do it in dhtml? Can I just pass “id” of the selected line in the 1st grid some how to “connector” or …? Please advice … I really stuck and can not find in documentation which direction to dig :frowning:

Thanks in advance
Regards
Igor

You should add an event to the parent grid that gets fired when a row is selected -
parentGrid.attachEvent(“onRowSelect”, function(rId,cInd){
// clear out an rows already in the grid
childGrid.clearAll();
childGrid.load("[name of server side script]&parentid=" + rId);
});

the server side script should use the DHTMLX connector code (presumably you already have this working in your first grid). You need to add the logic to the script to filter the results by the id of parent grid. eg -

// this method means the same script can be used to show all records from the child table or filter them if the “parentid” paramter is provided
$sqltext = “select * from [child table]”;

if (isset($parentid = $_GET[‘parentid’])) {
$sqltext = "select * from [child table] where parentid = $parentid ";
}

require("[path to connector]/php/codebase/grid_connector.php");
$res=mysql_connect(“localhost”,"[user]","[password]");
mysql_select_db("[databasename]");
$gridConn = new GridConnector($res,“MySQL”);

$gridConn->render_sql($sqltext,"[primary key from child table",“list of fields to return from child table”);

good luck
Paul