help!

Questionshelp!
pierre mata asked 9 years ago

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…

4 Answers
Abu Ghufran answered 9 years ago

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.

pierre mata answered 9 years ago

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"];
}

Abu Ghufran answered 9 years ago

This is because the on_after_insert, no insert query is further executed after that.
To update database in on_after_insert, you need to execute INSERT or UPDATE query.

Refer demos / editing / custom-event.php

Your Answer

1 + 17 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?