Jump to content

display multiple ID values from one url


SF23103

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.