PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
CerIs
Forum Newbie
Posts: 22 Joined: Sat May 29, 2004 9:20 am
Post
by CerIs » Tue Jun 08, 2004 1:37 pm
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>";
}
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++)
{
extract ($row);
echo "<td width='500'><img src='images/$Name'></td>";
}
Thanks Paul
?>
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Jun 08, 2004 1:48 pm
something like this?
Code: Select all
$cols = 3;
$c = 0;
while($row = mysql_fetch_assoc($result))
{
if($c == 0)
echo "<tr>";
echo "<td width="500"><img src="images/{$rowї'Name']}"></td>";
if($c == $cols - 1)
echo "</tr>";
$c++;
$c %= $cols;
}
CerIs
Forum Newbie
Posts: 22 Joined: Sat May 29, 2004 9:20 am
Post
by CerIs » Tue Jun 08, 2004 1:55 pm
Yeah thanks:) it still prints out all of the records though?
whats this bit doin if($c == $cols - 1) ?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Jun 08, 2004 1:59 pm
it checks to see if it's the last one for that table row..
CerIs
Forum Newbie
Posts: 22 Joined: Sat May 29, 2004 9:20 am
Post
by CerIs » Tue Jun 08, 2004 3:01 pm
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.
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Tue Jun 08, 2004 3:03 pm
just add 'LIMIT 3' to your query
CerIs
Forum Newbie
Posts: 22 Joined: Sat May 29, 2004 9:20 am
Post
by CerIs » Tue Jun 08, 2004 3:12 pm
Hehe
it works, thanks for the help.