Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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