Jump to content

MYSQL select help


beansandsausages

Recommended Posts

Hiya MYSQL freaks.

 

im just curious is it possible to select only selected records from a database. IE:

 

$select = mysql_query("SELECT * FROM `news` WHERE 'id'='1'")or die(mysql_error()); 
	while($woot= mysql_fetch_array( $select )) 

	{

 

All i want to know is in the db table nes there is 15 records, is there away to select by id like. if i only want posts with id 1,4,5 & 9?

 

rather that having several db query

 

Link to comment
https://forums.phpfreaks.com/topic/127957-mysql-select-help/
Share on other sites

There are two ways that come to mind that might suit you, the first is Bendude's, which may be a bit longer:

 

SELECT * FROM 'news' WHERE id='1' OR id='5' OR id='7' OR id='10'

 

OR you can use the MySQL IN() function

 

SELECT * FROM 'news' WHERE id IN ('1', '5', '7', '10')

 

or if you need a range:

 

SELECT * FROM 'news' WHERE id BETWEEN 1 AND 5

 

Hope that helps!

Link to comment
https://forums.phpfreaks.com/topic/127957-mysql-select-help/#findComment-662601
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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