Nned help - grid to two MySQL tables

Hi, I try to get through connector, but I lack documentation. I’m not able to do it with existing one, I was trying $conn->event->attach, $gridConn->render_sql, etc… Simply I can not do it :frowning:

My problem is: I have a grid, I want to send its data to two separate MySQL tables. Let’s say - collumns 0 and 1 of grid to table1 and columns 2 and 3 of grid to table 2.

How should I do it?

And vice versa, I want to get data from table1 to populate columns 0 and 1 of grid, and data from table 2 to populate columns 2 and 3 of grid.

Thank you for an answer!


Get part is simple - just use render_sql with joined tables

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

Saving is more complicated, as you need to do 2 save calls, you can define custom function through

function myupdate($action){ //custom code here } $conn->event->attach("beforeProcessing", "myupdate")
and in myupdate function exec necessary calls ( directly through db interface )

Dear Stanislav, thank you for your kind reply.

I just downloaded dhtmlx, so let my ask you more questions, which may help other newbiees as well. Let’s talk about first tutorial: http://docs.dhtmlx.com/doku.php?id=tutorials:dhtmlx_today:tut_dhtmlxstart - Contact manager.

There are two phone numbers. Suppose I want to make two tables, one with contact, as it is, but instead of phone numbers I want to keep in “phone_1” and “phone_2” just primary index from second table “phones”, where there is appropriate number. So in “phones”, there is primary index “p_i” and “number”.

Let’s say like this.
id fname lname company e-mail phone_1 phone_2…p_i …number
…0…1…0…987 654
…2…1…345 678
…3…0…2…123 456

What I want to do - in my contact table I don’t want to see indexes, but real numbers. And when I change/delete/insert the number, I want to update “phones” table as well.

Any idea?

You can use “co” column in grid, in place where you need to select phones and on server side while loading data in grid

a) create and configure GridConnector to load data from table Contacts
b) create OptionsConnector for table Phones and link it to master connector

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

Dear Stanislav, thank you for taking care.

However, I’m still not able to do, what I want :frowning:

Let me precise my questions.

1.) If I understood well, render_sql is responsible for uploading data from sql to grid, render_table is responsible for uploading data from db to grid?

2.) In above mentioned tutorial, I can edit grid directly, or via form. That means, I have watch just grid for changes, and those changes apply to connector and connector applies them to db?

3.) As for double save - connector.php consist of code for connecting to db, and then is
$gridConn = new GridConnector($res,“MySQL”);

I tried this:
function myupdate($action){$id = $action->get_id();
$val1 = $action->get_value(“Phone_1”);
$gridConn->mysql_query(“INSERT INTO Test (phone) VALUES {$val1}”);
$gridConn->event->attach(“beforeProcessing”, “myupdate”);

Doesn’t work :frowning:

Any help appreciated!

(1) both render sql and render table works in similar way, they will take data from db and output it in the components format, as xml ( or as json ) . The only difference is the sql code which is provided in command ( render_sql ) or autogenerated ( render_table )

(2) Yep. You can have different connectors for form and grid, but in most cases it doesn’t have sense to duplicate data saving logic.

(3) In your code

$gridConn->mysql_query("INSERT INTO Test (phone) VALUES {$val1}");

must be

global $gridConn; $gridConn->sql->query("INSERT INTO Test (phone) VALUES {$val1}");

and be sure that event->attach is placed before render_table

Hi Stanislav,

thanks again for your reply. Unfortunatelly, I’m still doing something wrong :frowning:

Here is my code, when I tested it without dhx, eveyrithing was fine, so probably I don’t have typo.


global $gridConn; 
function myupdate($action)
$id = $action->get_id();
$phone1 = $action->get_value("Phone_1");

$gridConn = new GridConnector($res,"MySQL");
$gridConn->sql->query("INSERT INTO test (phone_1) VALUES ($phone_1)");
$gridConn->event->attach("beforeProcessing", "myupdate");
//	$gridConn = new GridConnector($res,"MySQL");

render_table works, but I can’t get any insert to ‘test’ db. What is wrong?

Try to change the code as

[code]function myupdate($action){
global $gridConn;
$id = $action->get_id();
$phone1 = $action->get_value(“Phone_1”);

$gridConn->sql->query("INSERT INTO test (phone_1) VALUES ($phone_1)");


$gridConn = new GridConnector($res,“MySQL”);
$gridConn->event->attach(“beforeProcessing”, “myupdate”);

Also, I’m not sure about “$phone1 = $action->get_value(“Phone_1”);” - you have not this field in list of connector’s fields, so I’m not sure from which it will come - it must be one of fields defined in render_table or set as userdata on client side.