This topic is locked
[SOLVED]

 How To Update A Record Only If 2 Key Values Are Matched?

1/21/2013 2:21:51 AM
PHPRunner General questions
P
phpcmk author

Hi,
I have 2 tables named "master" and "slave".
I used phprunner to create 2 menus. User can enter the field in "slave" menu and "master" menu will automatically update with record.
When user click "edit" button in "slave" menu and changed the information, the "master" menu columns' value will also change accordingly. I used the following code by adding Param["identifier"]=$values["identifier"] and it works.
----------------------------------------------

In events>slave>Edit page>After record updated

----------------------------------------------

global $dal;

$dal_table = $dal->Table("master");

$dal_table->Param["identifier"]=$values["identifier"];

$dal_table->Value["name"] = $values["name"];

$dal_table->Value["address"] = $values["address"];

$dal_table->Value["age"] = $values["age"];

$dal_table->Update();

------------------------------------------------
However, I would like to update the column in "master" menu only if there are 2 columns' value match. I tried adding another Param["value"] but it is not working.Can anyone please kindly help? Thanks

-----------------------

global $dal;

$dal_table = $dal->Table("master");

$dal_table->Param["identifier"]=$values["identifier"];

$dal_table->Param["name"] = $values["name"];

$dal_table->Value["name"] = $values["name"];

$dal_table->Value["address"] = $values["address"];

$dal_table->Value["age"] = $values["age"];

$dal_table->Update();

C
cgphp 1/21/2013

Not sure what you mean when you say "only if there are 2 columns value match". Check the following solution:



$rs = CustomQuery("SELECT name FROM master WHERE identifier =".$values["identifier"]);

$rec = db_fetch_array($rs);
if($rec["name"] == $values["name"])

{

global $dal;

$dal_table = $dal->Table("master");

$dal_table->Param["identifier"]=$values["identifier"];

$dal_table->Param["name"] = $values["name"];

$dal_table->Value["name"] = $values["name"];

$dal_table->Value["address"] = $values["address"];

$dal_table->Value["age"] = $values["age"];

$dal_table->Update();

}


If identifier is a string the SELECT query becomes:

$rs = CustomQuery("SELECT name FROM master WHERE identifier ='".$values["identifier"]."'");