datafan Posted September 5, 2007 Share Posted September 5, 2007 Here is the website, www.goodstylist.com I am refering to the three pictures of "Todays Top Rated Stylists". what I am trying to do is figure out a clean way to start a new table row for each 3 Stylists. So if I change my query to pull 12 instead of just 3, the output on the screen will just loop creating rows of 3 like the one there. Here is what is driving it now: $query = sprintf("SELECT username, thpicname1, realname, city, state, currentrate FROM users WHERE(thpicname1 !='') ORDER BY currentrate DESC LIMIT 0,3"); // Perform Query GetMyConnection() or die(mysql_error()); $result = mysql_query($query); if (!$result) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $query; die($message); } echo "<table cellpadding='4' width='760'>"; echo "<tr>"; while ($row = mysql_fetch_assoc($result)) { $thumb = "files/userimages/" .$row['thpicname1']; echo "<td border='3' width='250'><a href='files/profileview.php?find=".$row['username']."' target='_self'><img src='".$thumb."'></a><br>" .$row['realname']. "<br>" . $row['city'] . " , " . $row['state'] . "<br>Current Rating " . $row['currentrate'] . "</td>"; } mysql_free_result($result); ?> </tr> </table><br> Thanks for any help, and how do you get your code to show up with all the colors here like it does in notepad++ ? Link to comment https://forums.phpfreaks.com/topic/68059-solved-a-good-way-to-loop-this-output/ Share on other sites More sharing options...
pocobueno1388 Posted September 5, 2007 Share Posted September 5, 2007 Change your while loop to this: <?php $i = 0; while ($row = mysql_fetch_assoc($result)) { $thumb = "files/userimages/" .$row['thpicname1']; if ($i == 3){ echo '<tr>'; $i=0;} echo "<td border='3' width='250'><a href='files/profileview.php?find=".$row['username']."' target='_self'> <img src='".$thumb."'></a><br>" .$row['realname']. "<br>" . $row['city'] . " , " . $row['state'] . " <br>Current Rating " . $row['currentrate'] . "</td>"; $i++; } ?> Link to comment https://forums.phpfreaks.com/topic/68059-solved-a-good-way-to-loop-this-output/#findComment-342100 Share on other sites More sharing options...
datafan Posted September 5, 2007 Author Share Posted September 5, 2007 Perfect! Thanks a ton! Link to comment https://forums.phpfreaks.com/topic/68059-solved-a-good-way-to-loop-this-output/#findComment-342102 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.