Old 20-05-2007, 10:17   #1 (permalink)
DrBurkstrom
Registered User
 
Join Date: Jan 2007
Posts: 32
mysql query help

I have a mysql table where the items all have an id field (obviously), and I want to select only those items whose id is contained in a php array.

Is this possible without iterating through the array and pulling each item out individually with it's own query?

Thanks
  Reply With Quote
Old 20-05-2007, 10:21   #2 (permalink)
RaelRode
Designers are strange :)
 
RaelRode's Avatar
 
Join Date: Jan 2007
Location: Shrewsbury, UK
Posts: 1,685
Send a message via ICQ to RaelRode Send a message via AIM to RaelRode Send a message via MSN to RaelRode Send a message via Yahoo to RaelRode Send a message via Skype™ to RaelRode
Just callt he one field "id" and put it in a loop. Not sure how to do this anymore but someone else may give a code example.
  Reply With Quote
Old 20-05-2007, 12:47   #3 (permalink)
gk
geek
 
gk's Avatar
 
Join Date: Oct 2006
Location: *.everywhere
Posts: 204
Send a message via ICQ to gk Send a message via AIM to gk Send a message via MSN to gk Send a message via Yahoo to gk
PHP Code:
$rs=mysql_query('SELECT * FROM table_name WHERE id IN (0,1,2,3,10)');
while(
$row=mysql_fetch_assoc($rs)){
//do stuff
echo "At row $id<br />\n";


The where will cause the statement to only select rows with ids of 0,1,2,3 and 10 rows 4,5,6,7,8 and 9 are all skipped.
__________________
Quote:
"Why reinvent the wheel"? Simply because it's not round enough and I don't like the treads.
  Reply With Quote
Old 20-05-2007, 13:12   #4 (permalink)
DrBurkstrom
Registered User
 
Join Date: Jan 2007
Posts: 32
Hah - So simple yet it's been completely eluding me! Thanks gk, that's just what I need!
  Reply With Quote
Old 20-05-2007, 13:26   #5 (permalink)
RaelRode
Designers are strange :)
 
RaelRode's Avatar
 
Join Date: Jan 2007
Location: Shrewsbury, UK
Posts: 1,685
Send a message via ICQ to RaelRode Send a message via AIM to RaelRode Send a message via MSN to RaelRode Send a message via Yahoo to RaelRode Send a message via Skype™ to RaelRode
See theres your loop!!!!!!!!!!
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8