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? Quote Link to comment 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?) Quote Link to comment 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>'; Quote Link to comment 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> Quote Link to comment 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>'; ?> Quote Link to comment Share on other sites More sharing options...
seany123 Posted June 29, 2011 Author Share Posted June 29, 2011 thankyou. Quote Link to comment 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.