Forum Moderators: coopster

Message Too Old, No Replies

selecting multiple rows from a table with where

mysqli and php5

         

John_Keates

11:58 am on Feb 10, 2006 (gmt 0)

10+ Year Member



Hi, I can't find out how to select multiple rows
(SQL: SELECT pid FROM photo_photos WHERE aid='1')
there are multiple rows with aid 1 so how do I get everything in an array?

omoutop

12:06 pm on Feb 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



hi John_Keates!

This is simple, you need a while loop in order to fetch all of them, for instance:

$select = "SELECT pid FROM photo_photos WHERE aid='1'";
$run = mysql_query($select) or die (mysql_error());
while ($row = mysql_fetch_assoc($run))
{ //loop starts
$pid = $row['pid'];
echo $pid;
} //loop ends

instead of :
$pid = $row['pid'];
echo $pid;

you can always use :

echo $row['pid'];

Try it out

John_Keates

12:17 pm on Feb 10, 2006 (gmt 0)

10+ Year Member



Thanks, now I understand how to use that query with a while.