Jump to content

Recommended Posts

Hi all

I have a field in my database called "id_nums" which store comma seperated values, such as

1,4,77,400

or

45,77,79,120,134

I then have a php query which looks like

[code]$sql = "SELECT * FROM products WHERE id = $id";[/code]

At the moment is basically is selecting all rows which match the id number, what I want to do is display all row id numbers which match the comma seperated value "id_nums".

So if it passed the value

45,77,79,120,134

it would display all the rows with those id numbers

I made

[code]$sql = "SELECT * FROM products WHERE id = $id_nums";[/code]

But it doesnt seem to be able to do multiple selecting this way.

Can anyone help?

Thanks in advance

Dave
Link to comment
https://forums.phpfreaks.com/topic/10382-multiple-ids/
Share on other sites

not sure i entirely understand the question, but say you had an array of numbers

[b]$numbers = array('45','77','79','120','134');[/b]

you can implode it into a single comma seperated string like so:

[b]$list = implode(",", $numbers);[/b]

then you should be able to do this:

[b]$sql = "SELECT * FROM products WHERE id IN ('$list')";[/b]

did i understand your question right?
Link to comment
https://forums.phpfreaks.com/topic/10382-multiple-ids/#findComment-38682
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.