I received two associative array and I want to update it's values in mysql db. So, I did this:
// for all other contacts
if(isset($_POST['otherAddress']) || isset($_POST['otherComments']))
{
$otherAddress = $_POST['otherAddress'];
$otherComments = $_POST['otherComments'];
foreach (array_keys($otherAddress + $otherComments) as $key)
{
$query = "UPDATE `boardcontacts` SET
`address`='$otherAddress[$key]',`comments`='$otherComments[$key]'
WHERE `memberID` = '$nID' AND `addressType`='other'";
mysql_query($query);
} // for end
} // if end
Problem is: It duplicate all updated rows with the last index of each array. Any help ?
Just curious are you updating the value of $nID
??
Because if the foreach
executes without updating $nID
the query will update the values in the same row every time because the where
condition is same every time.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.