Hi all,
I have 2 array which populated from MYSQL as shown below :
My program will update status in the temporary table according to
compare of 2 arrays, for example from 2 array below:
in $temptablearr = there 3 elements
in $currenttablearr = there 2 elements
If value different betweeen elements in the $temptablearr and
$currenttablearr , the status is change to 'update'.
If value are same between $temptablearr and $currenttablearr , no
action taken.
If there are new elements in $temptablearr and not found in
$currenttablearr, the status is change to 'new'
If there are elements found in $currenttablearr and not found in
$temptablearr , the status is change to 'deleted'
Anyone have any ideas or suggestion how to do this ? Thanks for your help.
$temptablearr = array(0 =>
array("chassis_serial_no"=>"1235",
"country"=>"Malaysia",
"card_serial_no"=>"cd-12345",
"card_model"=>"ws8950"),
1 =>
array("chassis_serial_no"=>"1235",
"country"=>"Malaysia",
"card_serial_no"=>"cd-890",
"card_model"=>"ws1234"),
2 =>
array("chassis_serial_no"=>"8888",
"country"=>"Indonesia",
"card_serial_no"=>"cd-12345",
"card_model"=>"ws999"),
);
$currenttablearr = array( 0 =>
array("chassis_serial_no"=>"1235",
"country"=>"Malaysia",
"card_serial_no"=>"cd-12345",
"card_model"=>"ws8950"),
1=>
array("chassis_serial_no"=>"1235",
"country"=>"Singapore",
"card_serial_no"=>"cd-890",
"card_model"=>"ws1234"),
);
Below is my test code .
<?php
$temptablearr = array(0 =>
array("chassis_serial_no"=>"1235",
"country"=>"Malaysia",
"card_serial_no"=>"cd-12345",
"card_model"=>"ws8950"),
1 =>
array("chassis_serial_no"=>"1235",
"country"=>"Malaysia",
"card_serial_no"=>"cd-890",
"card_model"=>"ws1234"),
2 =>
array("chassis_serial_no"=>"8888",
"country"=>"Indonesia",
"card_serial_no"=>"cd-12345",
"card_model"=>"ws999"),
);
$currenttablearr = array( 0 =>
array("chassis_serial_no"=>"1235",
"country"=>"Malaysia",
"card_serial_no"=>"cd-12345",
"card_model"=>"ws8950"),
1=>
array("chassis_serial_no"=>"1235",
"country"=>"Singapore",
"card_serial_no"=>"cd-890",
"card_model"=>"ws1234"),
);
$compare = true;
foreach($temptablearr as $key => $val)
{
if($currenttablearr[$key] != $val) {
$compare = false;
}
if($compare === false) {
echo 'update status in table to update<br><br>';
}else
if($compare === true){
echo 'skip, do not shown in page.<br><br>';
}
}
?>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php