Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Programming/Scripts

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 11th December 2009, 16:04
edge edge is offline
Moderator
 
Join Date: Dec 2005
Location: The Netherlands
Posts: 2,042
Thanks: 269
Thanked 154 Times in 133 Posts
Unhappy PHP: Show 3 records from MySQL (exampel: ID: 5 22 87)

I'm feeling so stupid at the moment, but what's the best way to get MySQL to show lets say 3 records.

Example: I want to show record ID 5, 22 and 87 in on go.

Sure I can do a query loop on each record like this
Code:
$query_rsFiles = "SELECT * FROM products WHERE `ID` = '$the_ID'";
or get MySQL to do a query on all records , and when the ID is 5 or 22 or 87 are up to show the data, but this looks like a long and not proper way to do it.

Anyone here who might know the correct way of doing this?

Once again.. Sorry for asking this... I know.. I should know things like this.
Reply With Quote
Sponsored Links
  #2  
Old 11th December 2009, 16:11
edge edge is offline
Moderator
 
Join Date: Dec 2005
Location: The Netherlands
Posts: 2,042
Thanks: 269
Thanked 154 Times in 133 Posts
Default

Nevermind..

Found it I think..

$query_rsFiles = "SELECT * FROM products WHERE `ID` = '5' OR `ID` = '22' OR `ID` = '87'";

Not sure if OR is the best way to do it.
Reply With Quote
  #3  
Old 11th December 2009, 21:05
id10t id10t is offline
Senior Member
 
Join Date: Nov 2008
Posts: 242
Thanks: 2
Thanked 22 Times in 22 Posts
Default

select * from table where id=('5','22','87')

You aren't really playing with PHP at this point, you are playing wtih SQL statements.
__________________
I'm a very happy linode.com customer, I'm sure you will be too!
Reply With Quote
The Following User Says Thank You to id10t For This Useful Post:
edge (12th December 2009)
  #4  
Old 12th December 2009, 14:59
topdog topdog is offline
Senior Member
 
Join Date: Jan 2008
Location: South Africa
Posts: 1,352
Thanks: 0
Thanked 154 Times in 151 Posts
Default

actually is it
Code:
select * from table where id IN (5,22,87)
as id is most likely a numeric value not a string.
__________________
----
http://www.topdog.za.net - Got Linux problems ? - I can help.
http://www.baruwa.org - Try it.
Reply With Quote
The Following User Says Thank You to topdog For This Useful Post:
edge (12th December 2009)
  #5  
Old 12th December 2009, 17:52
edge edge is offline
Moderator
 
Join Date: Dec 2005
Location: The Netherlands
Posts: 2,042
Thanks: 269
Thanked 154 Times in 133 Posts
 
Default

The OR that I'm using at the moment is working fine, but for sure I will give IN also a go,
And yes.. The ID is a numeric value.

Thank you both for your answer.
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Newly Installed ISPConfig3 on Ubuntu 8.04 : login redirect fail ? cripperz Installation/Configuration 5 22nd March 2009 13:15
add web site serr57 Installation/Configuration 18 13th April 2008 12:40
php eating cpu shajazzi Server Operation 15 15th August 2007 02:19
Virtual Hosting Not Working stirfry Installation/Configuration 26 7th August 2007 11:53
VirtualHosts marra87 General 9 12th September 2006 05:09


All times are GMT +2. The time now is 18:02.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.