Jump to content

MYSQL select help


burnside

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