Update one table, select several tables,

hello

I need update one table, but I need the select of my data store of several tables.
example:

I have a store , key city an key deparment

$data->render_table(“mn_mfarmacias”,“con”,“nombre,sucursal,direccion,telefono,id_depto,id_ciudad,nit,estado”);

execute this update OK , but I need the name of the city and departmet, for return a DHTMLXGrid

help, thanks.

Hi ivomat,
I used this code to execute a customize query on a grid connector and seems to work quite well for loading…

if ($conn->is_select_mode())//code for loading data $conn->render_sql("SELECT evaluation.id AS id,evaluation.dim AS dim,evaluation.title AS title,evaluation_data.value AS Sol_1 FROM evaluation LEFT JOIN evaluation_data ON evaluation.id=evaluation_data.id_eval", "a.id","id,dim,title,Sol_1");

Yep, the above suggestion is correct. You can use is_select_mode method to define two different instructions - one for data loading ( with several tables ), another for data updates

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

thanks for response …

<?php error_reporting(E_ALL ^ E_NOTICE); require_once('../../includes/conexion.inc'); require_once('../../includes/dhtmlxConnector/codebase/data_connector.php'); $data = new JSONDataConnector($conn, "MySQL"); $data->enable_log("/home/p16h9sqv/public_html/medi-net.co/descargas/log.txt"); if ($data->is_select_mode()){ $data->render_sql("select con,sucursal, nombre,direccion,telefono, depto.depto as depto,ciudad.id_depto as id_depto, ciudad.ciudad as ciudad , ciudad.id as id_ciudad , CASE estado WHEN 1 THEN 'Activo' WHEN 0 THEN 'Inactivo' END AS estadon, estado , nit from mn_mfarmacias f, mn_mdepto depto,mn_mciudad ciudad where f.id_depto= ciudad.id_depto and f.id_ciudad = ciudad.id and depto.id = ciudad.id_depto order by f.sucursal asc","con","nombre,sucursal,direccion,telefono,depto,id_depto,ciudad,id_ciudad,nit,estado,estadon"); } else { $data->render_table("mn_mfarmacias","con","nombre,sucursal,direccion,telefono,id_depto,id_ciudad,nit,estado"); } update the key the city and deparmet , but in the GRID not update the names,

The above solution will work if you have same order of fields in the render_sql, and render_table fields, which will be problematic in your case.

Try to change your code like next

[code]$data->sql->attach(“Update”, “UPDATE mn_mfarmacias SET nombre=’{nombre}’ WHERE con=’{con}’”;

$data->render_sql(“select con,sucursal, nombre,direccion,telefono, depto.depto as depto,ciudad.id_depto as id_depto, ciudad.ciudad as ciudad , ciudad.id as id_ciudad , CASE estado WHEN 1 THEN ‘Activo’ WHEN 0 THEN ‘Inactivo’ END AS estadon, estado , nit from mn_mfarmacias f, mn_mdepto depto,mn_mciudad ciudad where f.id_depto= ciudad.id_depto and f.id_ciudad = ciudad.id and depto.id = ciudad.id_depto order by f.sucursal asc”,“con”,“nombre,sucursal,direccion,telefono,depto,id_depto,ciudad,id_ciudad,nit,estado,estadon”);[/code]

If it works, you can add all necessary fields in the first query

not working properly, do not perform the update

if ($data->is_select_mode()){
$query = “select con,sucursal, nombre,direccion,telefono, depto.depto as depto,ciudad.id_depto as id_depto, ciudad.ciudad as ciudad , ciudad.id as id_ciudad , CASE estado WHEN 1 THEN ‘Activo’ WHEN 0 THEN ‘Inactivo’ END AS estadon, estado , nit from mn_mfarmacias f, mn_mdepto depto,mn_mciudad ciudad where f.id_depto= ciudad.id_depto and f.id_ciudad = ciudad.id and depto.id = ciudad.id_depto order by f.sucursal asc”;
$data->render_sql($query,“con”,“nombre,sucursal,direccion,telefono,id_depto,depto,id_ciudad,ciudad,nit,estadon,estado”,“id_ciudad,id_depto,estado”);
}
else {
$data->sql->attach(“Update”, “UPDATE mn_mfarmacias SET nombre=’{nombre}’ WHERE con=’{con}’”);
}

Please try to place them in the same order as was described above

$query = "select con,sucursal, nombre,direccion,telefono, depto.depto as depto,ciudad.id_depto as id_depto, ciudad.ciudad as ciudad , ciudad.id as id_ciudad , CASE estado WHEN 1 THEN 'Activo' WHEN 0 THEN 'Inactivo' END AS estadon, estado , nit from mn_mfarmacias f, mn_mdepto depto,mn_mciudad ciudad where f.id_depto= ciudad.id_depto and f.id_ciudad = ciudad.id and depto.id = ciudad.id_depto order by f.sucursal asc";

$data->sql->attach("Update", "UPDATE mn_mfarmacias SET nombre='{nombre}' WHERE con='{con}'");
$data->render_sql($query,"con","nombre,sucursal,direccion,telefono,id_depto,depto,id_ciudad,ciudad,nit,estadon,estado","id_ciudad,id_depto,estado");

this will instruct to use render_sql for all operation, except of update, for which the custom sql query will be used.

Hi.
please help me
the addition does not work properly, all fields are blank.

myForm.attachEvent(“onButtonClick”, function(id){
if (id==‘add’){ //adding custom blur event, with overwriting existing
farmacias.add({}); //creates a new record that uses

}

log
INSERT INTO mn_mfarmacias(nombre,sucursal,direccion,telefono,id_depto,id_ciudad,nit,estado) VALUES (’’,’’,’’,’’,’’,’’,’’,’’)

The above line was for update, similar it possible to use

$data->sql->attach("Insert", "INSERT INTO mn_mfarmacias(nombre) VALUES('{nombre}')");

Hi
please

as I get the id of the insert latter one???

$data->event->attach(“afterInsert”,“email”);
$data->sql->attach(“Insert”, “INSERT INTO mn_musuarios(con,nombre,login,frecuencia,mail,rid,estado,fecha_adicion)VALUES(’{id_punto}’,’{nombre}’,’{login}’,’{frecuencia}’,’{mail}’,’{id_rol}’,’{estado}’,now())”);

function email($row){
$id_u = mysql_insert_id();
$row->success();
mysql_query(“insert into mn_musuarios_menu select $id_u , id_menu,1 from mn_rolmenu where estado = 1 and id_rol = ‘$id_rol’”);
$row->success();
}

$id_u I did not bring the value

thanks

change it like next

function email($row){ $id_u = mysql_insert_id(); $row->success($id_u); }