bothwell Posted July 6, 2008 Share Posted July 6, 2008 I've been trying to get this working for a while now without any success - it used to work for PHP4, but PHP5, alas, has no truck with my sloppy indices. I need to update every area_id for a given tenant_id. So Jack is associated with area_ids 1 and 5 in the database, and I want to update him to 4 and 8 - using this code, I update him to 8 and 8, so the final item in the array goes into the DB twice. foreach ($strAreas as $areaval) { $dbAreaUpdate = "UPDATE area_mapping SET area_id=$areaval WHERE tenant_id = $strID "; mysql_query($dbAreaUpdate) or die ("area mapping error!"); } I know that this is because "SET area_id=$areaval" isn't paging through the array - but I don't know how to get it to do so, since I thought that was the point of the foreach. :/ Any help is appreciated Link to comment https://forums.phpfreaks.com/topic/113437-iterative-database-update-syntax-help/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.