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?] Quote Link to comment 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 Quote Link to comment 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']) .") Quote Link to comment Share on other sites More sharing options...
irkevin Posted March 25, 2010 Share Posted March 25, 2010 Did the code I posted work then? Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.