I am probably using the incorrect syntax for this, but I'm trying to to update the value in a column (dep_total) of a detail grid when an update occurs in a specified row:
$e["on_update"] = array("update_deptotal", null, true);
$g->set_events($e);
function update_deptotal($data)
{
$str = "UPDATE tour_pay SET dep_total = {$data["dep1"]}+{$data["dep2"]}+{$data["dep3"]}+{$data["dep4"]}
WHERE id = {$data["id"]}";
mysql_query($str);
}
These are the posted params (the id, first col, value of the detail grid is correct:
Array
(
[id] => 4
[params] => Array
(
[fname] => Paul
[lname] => Baumgarten
[hotel] => 0.00
[bus] => 0.00
[est_cost] => 0.00
[dep1] => 50.00
[dep1_nbr] => 0
[dep2] => 0.00
[dep2_nbr] => 0
[dep3] => 0.00
[dep3_nbr] => 0
[dep4] => 0.00
[dep4_nbr] => 0
[dep_total] =>
)
)
{"id":"'4'","success":true}
By looking at array, $data["id"] is fine. All rest param of query need correction.
$data["params"]["dep1"], $data["params"]["dep2"], $data["params"]["dep3"] and $data["params"]["dep4"].
The ["params"] key is missing in your query.
Thanks, I have modified as shown below:
$e["on_update"] = array("update_deptotal", null, true);
$g->set_events($e);
function update_deptotal($data)
{
$str = "UPDATE tour_pay SET dep_total = '{$data["params"]["dep1"]} + {$data["params"]["dep2"]} + {$data["params"]["dep3"]} + {$data["params"]["dep4"]}' WHERE id = {$data["id"]}";
mysql_query($str);
}
The dep_total is not being updated.
The returned array:
Array
(
[id] => 4
[params] => Array
(
[fname] => Paul
[lname] => Baumgarten
[hotel] => 0.00
[bus] => 0.00
[est_cost] => 0.00
[dep1] => 50.00
[dep1_nbr] => 0
[dep2] => 0.00
[dep2_nbr] => 0
[dep3] => 0.00
[dep3_nbr] => 0
[dep4] => 0.00
[dep4_nbr] => 0
[dep_total] =>
)
)
{"id":"'4'","success":true}
In your event handler, add echo statement as mentioned below, and check the firebug ajax response when you update grid.
This would show exact query and reason for not updating.
function update_deptotal($data)
{
$str = "UPDATE tour_pay SET dep_total = '{$data["params"]["dep1"]} + {$data["params"]["dep2"]} + {$data["params"]["dep3"]} + {$data["params"]["dep4"]}' WHERE id = {$data["id"]}";
echo $str;
mysql_query($str);
echo mysql_error();
}