Page 1 of 1

Geting multiple rows

Posted: Tue Jun 08, 2004 1:37 pm
by CerIs
Im trying to get multiple rows from mysql and echo them out.

This works but i dont want all of the rows at once

Code: Select all

while($row = mysql_fetch_array($result))

{ 
 extract ($row);
 echo "<td width='500'><img src='images/$Name'></td>";
 
 &#125;
when i try this for loop it doesnt work. It just prints out the first image 3 times?

Code: Select all

for($i = 1; $i <= 3; $i++)

&#123; 
 extract ($row);
  echo "<td width='500'><img src='images/$Name'></td>";
 
 &#125;
Thanks Paul
?>

Posted: Tue Jun 08, 2004 1:48 pm
by feyd
something like this?

Code: Select all

$cols = 3;
$c = 0;
while($row = mysql_fetch_assoc($result))
{
  if($c == 0)
    echo "&lt;tr&gt;";
  echo "&lt;td width="500"&gt;&lt;img src="images/{$row&#1111;'Name']}"&gt;&lt;/td&gt;";
  if($c == $cols - 1)
    echo "&lt;/tr&gt;";
  $c++;
  $c %= $cols;
}

Posted: Tue Jun 08, 2004 1:55 pm
by CerIs
Yeah thanks:) it still prints out all of the records though?

whats this bit doin if($c == $cols - 1) ?

Posted: Tue Jun 08, 2004 1:59 pm
by feyd
it checks to see if it's the last one for that table row..

Posted: Tue Jun 08, 2004 3:01 pm
by CerIs
is there a way to do it without using

while($row = mysql_fetch_assoc($result))

beause i only want to get 3 rows from the database.

Posted: Tue Jun 08, 2004 3:03 pm
by Weirdan
just add 'LIMIT 3' to your query

Posted: Tue Jun 08, 2004 3:12 pm
by CerIs
Hehe :) it works, thanks for the help.