Forum Moderators: coopster

Message Too Old, No Replies

Need Help for Looping

         

Shanee

9:06 pm on Jul 24, 2006 (gmt 0)

10+ Year Member



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

barns101

9:18 pm on Jul 24, 2006 (gmt 0)

10+ Year Member



Thanks to jatar_k - [webmasterworld.com...]


$sql = "select * from sometable";
$result = mysql_query($sql);
$tdcount = 1;
$numtd = 3; // number of cells per row
echo "<table>";
while($row = mysql_fetch_array($result)) {
if ($tdcount == 1) echo "<tr>";
echo "<td>some stuff: $tdcount</td>"; // display as you like
if ($tdcount == $numtd) {
echo "</tr>";
$tdcount = 1;
} else {
$tdcount++;
}
}
// time to close up our table
if ($tdcount!= 1) {
while ($tdcount <= $numtd) {
echo "<td>&nbsp;</td>";
$tdcount++;
}
echo "</tr>";
}
echo "</table>";

Shanee

9:38 pm on Jul 24, 2006 (gmt 0)

10+ Year Member



Wow..... its working

thanks barns101