SF23103 Posted April 27, 2013 Share Posted April 27, 2013 I'm working on an application that prints a fields from rows of a MySQL database. There is a checkbox next to each row. For each checkbox selected, it sends the unique row ID to the next page in the format display.php?checked=111&checked=222&checked=333 Of course, if I use $query="SELECT * FROM list WHERE id = $checked"; then it obviously only displays the first one (in the above example, row with ID 111) What is the best way to accomplish this? Do I need to totally re-think how I'm doing this, or is there away to allow $checked to have multiple values and get all of those values from the DB? Link to comment https://forums.phpfreaks.com/topic/277368-display-multiple-id-values-from-one-url/ Share on other sites More sharing options...
DavidAM Posted April 27, 2013 Share Posted April 27, 2013 You can make it an array: <INPUT type="checkbox" name="checked[]" ...>Then collect them when you get to the other page: $checkedList = implode(',', $_GET['checked']); $query = "SELECT * FROM list WHERE id IN ($checkedList)"; Of course, you should still validate to make sure the submitted data is valid and safe before sticking it in a query Link to comment https://forums.phpfreaks.com/topic/277368-display-multiple-id-values-from-one-url/#findComment-1426890 Share on other sites More sharing options...
SF23103 Posted April 27, 2013 Author Share Posted April 27, 2013 Ha! Wonderful, thank you. I thought an array was the answer, but I needed a little nudge. Link to comment https://forums.phpfreaks.com/topic/277368-display-multiple-id-values-from-one-url/#findComment-1426893 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.