two primary keys and there are two or more similar records in the same table

Questionstwo primary keys and there are two or more similar records in the same table
Cristian Engelmann asked 12 months ago

Hi Abu,

How can I update a specific record that has two primary keys?

when i update a record that has two primary keys and save the record, i look at the table and all the records that have the same key have changed. does not honor the two primary keys.
$g[“on_update”] = array(“update_data”, null, true);
$grid->set_events($g);

function update_data($data)
{
global $grid,$cid;
$codigo_producto = $data[“codigo_producto”];
$stock_minimo =  $data[“params”][“stock_minimo”];
$stock_maximo =  $data[“params”][“stock_maximo”];
$reposicion =  $data[“params”][“reposicion”];
$valorcosto =  $data[“params”][“valorcosto”];
$cantidad =  $data[“params”][“cantidad”];
$Sql = “UPDATE octmp SET cantidad=$cantidad,stock_minimo=$stock_minimo,stock_maximo=$stock_maximo,reposicion=$reposicion,valorcosto=$valorcosto where n_ordencompra = $cid AND codigo_producto = ‘$codigo_producto'”;
$result = $grid->execute_query($Sql);
}

1. I create two different orders
(sent you email the image)
2. I change one order number 3305
(sent you email the image)
3. I look the table and were changed two different records. (It were about orders 3305 and 3306)
(sent you email the image)

Could do you help me?

Thank you

2 Answers
Abu Ghufran Staff answered 11 months ago

To debug the callback function, You can put:
function update_data($data)

{

phpgrid_error($data);

}

This will show what keys and data are there in $data var. It will help in debug.

You can also debug SQL query before executing same way.

Second, If your complete update logic is inside this callback and you wish to skip the default grid implementation of update, You should set:

$g[“on_update”] = array(“update_data”, null, false);

$grid->set_events($g);

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Cristian Engelmann answered 11 months ago

Hi Abu,

It’s working

Thank you

Your Answer

3 + 5 =

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?