Jump to content

Need Help for Looping


shanee

Recommended Posts

hello....

i am newbie to php and have problem this is a loop for my wallpaper thumbs

 

<?php

$sql = "select wallpaperid from wallpaper";

$result = mysql_query($sql ,$db);

if ($myrow = mysql_fetch_array($result)) {

do {

printf("<td><a href='%s'><img src='images/sample/%s.jpg' border='0'></td>", $myrow["wallpaperid"], $myrow["wallpaperid"]);

 

} while ($myrow = mysql_fetch_array($result));

 

}

?>

 

if i have 6 pictures in database it will show like this

 

Image1.gif

Image2.gif

Image3.gif

Image4.gif

Image5.gif

Image6.gif

 

but i want it show the result like this in table

 

Image1.gif Image2.gif Image3.gif Image4.gif

Image5.gif Image6.gif

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/51888-need-help-for-looping/
Share on other sites

<?php

$sql = "select wallpaperid from wallpaper";
$result = mysql_query($sql ,$db);

while ($myrow = mysql_fetch_assoc($result)) {

printf("<td><a href='%s'><img src='images/sample/%s.jpg' border='0'></td>", $myrow["wallpaperid"], $myrow["wallpaperid"]);

}

?>

 

Try that

Link to comment
https://forums.phpfreaks.com/topic/51888-need-help-for-looping/#findComment-255758
Share on other sites

<?php

$sql = "select wallpaperid from wallpaper";
$result = mysql_query($sql ,$db);
$x=0;

while ($myrow = mysql_fetch_assoc($result)) 
{
    if ($x == 2)
    {
        $x=0;
        echo "<tr>\n";
    }
    else if ($x < 2)
    {
        printf("<td><a href='%s'><img src='images/sample/%s.jpg' border='0'></td>", $myrow["wallpaperid"], $myrow["wallpaperid"]);
        $x++;
    }

}

?>

 

that should do it.

Link to comment
https://forums.phpfreaks.com/topic/51888-need-help-for-looping/#findComment-255770
Share on other sites

i have check it but it gives me following result

 

image1 image2

image3 image4

 

 

means it cant show more than 4 results but the mysql row contain upto 10 entries i also tries

 

$sql = "select wallpaperid from wallpaper order by wallpaperid desc limit 0,15";

 

but getting same result :(

Link to comment
https://forums.phpfreaks.com/topic/51888-need-help-for-looping/#findComment-255819
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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