shanee Posted May 17, 2007 Share Posted May 17, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/51888-need-help-for-looping/ Share on other sites More sharing options...
chigley Posted May 17, 2007 Share Posted May 17, 2007 <?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 Quote Link to comment https://forums.phpfreaks.com/topic/51888-need-help-for-looping/#findComment-255758 Share on other sites More sharing options...
shanee Posted May 17, 2007 Author Share Posted May 17, 2007 it works fine, but not fit with my needs actually i want to get below result image1 image2 image3 image4 image5 image6 image7 image8 Quote Link to comment https://forums.phpfreaks.com/topic/51888-need-help-for-looping/#findComment-255764 Share on other sites More sharing options...
flappy_warbucks Posted May 17, 2007 Share Posted May 17, 2007 <?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. Quote Link to comment https://forums.phpfreaks.com/topic/51888-need-help-for-looping/#findComment-255770 Share on other sites More sharing options...
shanee Posted May 17, 2007 Author Share Posted May 17, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/51888-need-help-for-looping/#findComment-255819 Share on other sites More sharing options...
Barand Posted May 17, 2007 Share Posted May 17, 2007 See http://www.phpfreaks.com/forums/index.php/topic,139336.msg591593.html#msg591593 just define NUMCOLS as 2 Quote Link to comment https://forums.phpfreaks.com/topic/51888-need-help-for-looping/#findComment-255825 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.