forumnz Posted January 26, 2008 Share Posted January 26, 2008 My script is meant to display row data from a db in columns of 5 rows. I just lists them in one column (one long list). Here is the code: <? echo "<div id=\"catdiv\">"; while($row = mysql_fetch_array($sql)) { $name = $row['name']; $a = $row['id']; $i = 0; if($i <= 4) { echo "<a class=\"two\" href=?cat=" . $a . ">" . $name . "</a><br/>"; $i++; } else { echo "<br/><br/></div><div id=\"catdiv\">"; $i = 0; } } echo "</div>"; } ?> Thanks a lot! Sam. Quote Link to comment https://forums.phpfreaks.com/topic/87881-solved-multiple-display-columns-data-from-db/ Share on other sites More sharing options...
sasa Posted January 26, 2008 Share Posted January 26, 2008 try <? echo "<div id=\"catdiv\">"; $i = 0; while($row = mysql_fetch_array($sql)) { $name = $row['name']; $a = $row['id']; echo "<a class=\"two\" href=?cat=" . $a . ">" . $name . "</a><br/>"; if (++$i == 5){ echo "<br/><br/></div>\n<div id=\"catdiv\">"; $i = 0; } } echo "</div>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/87881-solved-multiple-display-columns-data-from-db/#findComment-449629 Share on other sites More sharing options...
forumnz Posted January 26, 2008 Author Share Posted January 26, 2008 Thank you so much! Quote Link to comment https://forums.phpfreaks.com/topic/87881-solved-multiple-display-columns-data-from-db/#findComment-449631 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.