HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials

HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials (http://www.howtoforge.com/forums/index.php)
-   Programming/Scripts (http://www.howtoforge.com/forums/forumdisplay.php?f=7)
-   -   PHP: Show 3 records from MySQL (exampel: ID: 5 22 87) (http://www.howtoforge.com/forums/showthread.php?t=41746)

edge 11th December 2009 15:04

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.

edge 11th December 2009 15:11

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.

id10t 11th December 2009 20:05

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

You aren't really playing with PHP at this point, you are playing wtih SQL statements.

topdog 12th December 2009 13:59

actually is it
Code:

select * from table where id IN (5,22,87)
as id is most likely a numeric value not a string.

edge 12th December 2009 16:52

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.


All times are GMT +2. The time now is 17:39.

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