smerny Posted March 25, 2010 Share Posted March 25, 2010 So I have a long list of information, each record includes this: <input type=checkbox name=box[] value='" .$row['ID']. "'> How would I write the WHERE clause? ie WHERE [the ID has been checked?] Link to comment https://forums.phpfreaks.com/topic/196516-updating-based-on-array-of-checked-boxes/ Share on other sites More sharing options...
irkevin Posted March 25, 2010 Share Posted March 25, 2010 if(isset($_POST['submit'])){ foreach($_POST['box'] as $key => $boxes){ $_POST['box'][$key] = $myBox; $the_box = implode(', ',$_POST['box']); $sql = "UPDATE yourtable SET field = value WHERE id IN ($the_box)"; $result = mysql_query($sql) or die(mysql_error()); if($result){ echo 'Success' } } } It might be what your looking for. let me know Link to comment https://forums.phpfreaks.com/topic/196516-updating-based-on-array-of-checked-boxes/#findComment-1031782 Share on other sites More sharing options...
smerny Posted March 25, 2010 Author Share Posted March 25, 2010 actually did something similar on my own... didn't do any previous code like the foreach loop, just did: WHERE ID IN (". join(',',$_POST['box']) .") Link to comment https://forums.phpfreaks.com/topic/196516-updating-based-on-array-of-checked-boxes/#findComment-1031797 Share on other sites More sharing options...
irkevin Posted March 25, 2010 Share Posted March 25, 2010 Did the code I posted work then? Link to comment https://forums.phpfreaks.com/topic/196516-updating-based-on-array-of-checked-boxes/#findComment-1031800 Share on other sites More sharing options...
smerny Posted March 25, 2010 Author Share Posted March 25, 2010 i did not try it as i have a working solution, but looking at it quickly there seems to be atleast one problem... you are looping the entire code? at first i'm thinking... that's a lot of unnecessary queries... but then i see you did use "IN" which means you probably did not mean to do this EDIT: looking at it more, i am also not sure what you are attempting with "$_POST['box'][$key] = $myBox;" since i cannot see where $myBox is coming from. Link to comment https://forums.phpfreaks.com/topic/196516-updating-based-on-array-of-checked-boxes/#findComment-1031850 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.