Hello, can you tell what is wrong with this code,the field "closed" doesn't get the value.
$e["on_insert"] = array("add_foto2", null, true);
$grid->set_events($e);
function add_foto2(&$data){
global $grid;
$check_sql = "SELECT MAX(id) as c FROM fotos";
$rs = $grid->get_one($check_sql);
$data["params"]["closed"] = $rs["c"];
}
and can you show me the next code making the change for mysqli mode instead myqsl?
function add_client($data)
{
$check_sql = "SELECT count(*) as c from clients where LOWER(`name`) = '".strtolower($data["params"]["name"])."'";
$rs = mysql_fetch_assoc(mysql_query($check_sql));
if ($rs["c"] > 0)
phpgrid_error("Client already exist in database");
mysql_query("INSERT INTO clients VALUES (null,'{$data["params"]["name"]}','{$data["params"]["gender"]}','{$data["params"]["company"]}')");
}
thanks…
You can put some debugging in callback function to see the query result.
function add_foto2(&$data){
global $grid;
$check_sql = "SELECT MAX(id) as c FROM fotos";
$rs = $grid->get_one($check_sql);
ob_start();
print_r($rs);
$s = ob_get_clean();
phpgrid_error($s);
$data["params"]["closed"] = $rs["c"];
}
And after that, when you call the add from grid, see the ajax call response using firebug debugger.
It would show the result.
Thanks Abu, now works, but just in the "on_insert" event, if i try in the "on_after_insert" event, the field "closed" is not update, why???
$e["on_after_insert"] = array("add_foto2", null, true);
$grid->set_events($e);
function add_foto2(&$data){
global $grid;
$check_sql = "SELECT MAX(id) as c FROM fotos";
$rs = $grid->get_one($check_sql);
$data["params"]["closed"] = $rs["c"];
}