filch Posted November 24, 2008 Share Posted November 24, 2008 I have an array which consists of record id numbers. It looks like this: Array ( [0] => 12 [1] => 13 [2] => 14 [3] => 15 [4] => 16 [5] => 17 [6] => 18 [7] => 19 [8] => 20 [9] => 21 [10] => 22 [11] => 23 [12] => 24 ) I also have a 3D array created from checkboxes in a form which looks like this: Array ( [1] => Array ( [0] => 1 [1] => 1 [2] => 1 ) [2] => Array ( [0] => 1 [1] => 1 ) [3] => Array ( [0] => 1 ) [4] => Array ( [0] => 1 [1] => 1 ) [5] => Array ( [0] => 1 [1] => 1 [2] => 1 ) [6] => Array ( [0] => 1 ) [7] => Array ( [0] => 1 [1] => 1 ) [8] => Array ( [0] => 1 ) ) I am trying to create an update statement to an MySQL dB. I have the following: for($i=0;$i < count($linkID);$i++) { $id = $linkID[$i]; foreach ($a_id as $aid => $chosen) { foreach ($chosen as $sid => $v) { $query = "UPDATE userairportservices SET service_id_service = $v, SET airport_id_airport = $aid WHERE usr_id_users = $userid AND userairportservices_id = $id"; mysql_query($query) or die('Error, update of dB failed for user id: &userid'); } } } Now I use a similar piece of code for an insert statement and it works fine. This, however is an UPDATE, and it throws an error as it fails to update. The idea is that the for loop, grabs the first id for the first record that contains the matching usr_id and then the foreach loops actually update the record where the usr_id AND the userairportservices_id matchupdates the record and then goes to the next id. At least, that's the theory. By the way, this is to update a linking table between two related tables in a relational dB schema. Anyone see where I have gone brain dead and screwed this up? Cheers, Dave Link to comment https://forums.phpfreaks.com/topic/133976-nested-loops/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.