Jump to content


Photo

Multiple ID number query


  • Please log in to reply
2 replies to this topic

#1 Canman2005

Canman2005
  • Members
  • PipPipPip
  • Advanced Member
  • 669 posts

Posted 13 April 2006 - 04:50 PM

Hi all

I have some id numbers stored in a sql database under a field called "idnums", for example, one of my rows stores id numbers in field "idnums" in the following format

1,5,7,17

each number is a id number in another table.

I insert the id numbers from a multiple selection list on a form using the 'join' function.

I then have a php query which looks like

$query=MYSQL_QUERY("SELECT * FROM order");

I want to be able to select just the id numbers from the table "orders" that are stored in the "idnums" field, I thought I could do

$query=MYSQL_QUERY("SELECT * FROM order WHERE id = $idnums");

but it doesnt seem to be able to do that, how could I get it to do this?

Any help would be ace

Thanks in advance

Ed

#2 Honoré

Honoré
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts
  • LocationAntwerp - Belgium

Posted 13 April 2006 - 05:05 PM

Try something like:
$query=MYSQL_QUERY("SELECT * FROM order WHERE id IN ( $idnums )");


#3 Canman2005

Canman2005
  • Members
  • PipPipPip
  • Advanced Member
  • 669 posts

Posted 13 April 2006 - 05:17 PM

[!--quoteo(post=364483:date=Apr 13 2006, 06:05 PM:name=Honoré)--][div class=\'quotetop\']QUOTE(Honoré @ Apr 13 2006, 06:05 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Try something like:
$query=MYSQL_QUERY("SELECT * FROM order WHERE id IN ( $idnums )");
[/quote]
Thank you, worked great




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users