xionhack Posted January 12, 2009 Share Posted January 12, 2009 Hello, let's say I have an array with the values Array ( [147] => 1 [148] => [149] => 6 [150] => [151] => ) When trying to update a mysql database, let's say I have two fields 'id' and 'team_id'. What I want is for example, the one with the 'id' = 147, the team_id to be updated to '1', id 148 has nothing set so no update will happen, 149 will be updated to 6, 150 and 151 will have no change. How can I do that? Please let me know if you couldnt understand. Thanks. Link to comment https://forums.phpfreaks.com/topic/140464-array-value/ Share on other sites More sharing options...
ratcateme Posted January 12, 2009 Share Posted January 12, 2009 try: foreach($array as $id => $team_id){ if($team_id != null){ mysql_query("UPDATE `table` SET `team_id` = {$team_id} WHERE ID = {$id}") or die(mysql_error()); } } Scott. Link to comment https://forums.phpfreaks.com/topic/140464-array-value/#findComment-735099 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.