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
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.