seany123 Posted June 28, 2011 Share Posted June 28, 2011 while ($query_result = mysql_fetch_array($query)) { echo "1"; echo "<br/>"; } this lists all the results in 1 column, but i was wondering how i can make the results go across 3 columns before going down? Link to comment https://forums.phpfreaks.com/topic/240623-while-loop-list-in-3-columns/ Share on other sites More sharing options...
WebStyles Posted June 28, 2011 Share Posted June 28, 2011 How would you like that? with just text and spaces, or with an html table? (what fields does $query_result return?) Link to comment https://forums.phpfreaks.com/topic/240623-while-loop-list-in-3-columns/#findComment-1235919 Share on other sites More sharing options...
TeNDoLLA Posted June 28, 2011 Share Posted June 28, 2011 Maybe I misunderstood, but anyway.. $i = 1; while ($query_result = mysql_fetch_array($query)) { echo "1"; if ($i%3 === 0) echo "<br/>"; $i++; } or maybe this helps.. echo '<table border="1"><tr>'; $i = 1; while ($i < 20) { echo '<td>'. $i .'</td>'; if ($i%3 === 0) { echo "</tr><tr>"; } $i++; } echo '</tr></table>'; Link to comment https://forums.phpfreaks.com/topic/240623-while-loop-list-in-3-columns/#findComment-1235921 Share on other sites More sharing options...
seany123 Posted June 28, 2011 Author Share Posted June 28, 2011 How would you like that? with just text and spaces, or with an html table? (what fields does $query_result return?) preferably inside html table but im not too fussed, i currently have something like this... but i dont know how to to <tr> $i = 1; <html> <table> <td id="1"></td> <td id="2"></td> <td id="3"></td> <?php while ($query_result = mysql_fetch_array($query)) { echo $i; ?> <td id="<?=$i?>"> <?php echo $i; echo "<br/>"; echo "</td>"; $i++; if ($i >= 4){ $i = 1; } } ?> </table> Link to comment https://forums.phpfreaks.com/topic/240623-while-loop-list-in-3-columns/#findComment-1235922 Share on other sites More sharing options...
WebStyles Posted June 28, 2011 Share Posted June 28, 2011 Was doing sort of the same, but TeNDoLLA beat me to it. I prefer to grab the database stuff firts, and then loop through it and add formatting or whatever. (you need to add the database fields) <?php $results = array(); while ($query_result = mysql_fetch_array($query)) { $results[] = $query_result; } $count = 0; echo '<table><tr>'; foreach ($results as $val){ $count++; if($count % 3 === 0) echo '</tr><tr>'; echo '<td nowrap="nowrap">'.$val.'</td>'; } echo '</tr></table>'; ?> Link to comment https://forums.phpfreaks.com/topic/240623-while-loop-list-in-3-columns/#findComment-1235923 Share on other sites More sharing options...
seany123 Posted June 29, 2011 Author Share Posted June 29, 2011 thankyou. Link to comment https://forums.phpfreaks.com/topic/240623-while-loop-list-in-3-columns/#findComment-1236215 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.