billgod Posted June 29, 2012 Share Posted June 29, 2012 I hope this has never been answered before but I don't even know what to look for.. here is what I am doing. database is doing a select to grab all names in db and putting checkbox next to them. checkbox value is the id - unique key echo "<tr><td><input type='checkbox' name='$rows[id]' value='$rows[id]'></td> <td> $rows[col_name]</td></tr>"; when I submit the form.. I need to find all that have check boxes and update the database. How can I do this without having to do if ($_POST[2]==2) or some crazy thing like that. anyone out there know an EASY way to do this? yes I suck as a coder but this is for personal stuff not for a enterprise type site. Quote Link to comment https://forums.phpfreaks.com/topic/264979-dont-even-know-how-to-ask-it/ Share on other sites More sharing options...
requinix Posted June 29, 2012 Share Posted June 29, 2012 Use an array: print_r($_POST['check']); Quote Link to comment https://forums.phpfreaks.com/topic/264979-dont-even-know-how-to-ask-it/#findComment-1357878 Share on other sites More sharing options...
Psycho Posted June 29, 2012 Share Posted June 29, 2012 And to build upon the array example, it is a simple operation to create a query to update all the records in mass. Just use IN within the query's WHERE clause and implode the IDs. Of course you should run the array through a process to force them to be ints to prevent SQL injection. //Force array values to integers and remove 0 values $submittedIDs = array_filter(array_map('intval', $_POST['check'])); //Convert to comma separated string $IDlistStr = implode(', ', $submittedIDs); //Create UPDATE array $query = "UPDATE table_name SET fieldname = 'somevalue" WHERE id IN ($IDlistStr)"; Quote Link to comment https://forums.phpfreaks.com/topic/264979-dont-even-know-how-to-ask-it/#findComment-1357892 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.