CoffeeAddict Posted March 8, 2007 Share Posted March 8, 2007 I have a lists of states being pulled from the database and displayed in one long column. How can I break it up so they appear in multiple columns next to each other? You can see what I mean here. All fifty states stretch the page out too much. I'd rather there be 15 in each column. This is the code for that area: <TR BGCOLOR="#FFFFCC"><TD colspan=2><P ALIGN=CENTER><B><FONT SIZE="-1" FACE="Arial,Helvetica,Geneva,Sans-serif,sans-serif">View all listings in an area</TD></TR> <TR> <TD COLSPAN=2 VALIGN=TOP><P><FONT SIZE="-1" FACE="Arial,Helvetica,Geneva,Sans-serif,sans-serif"> <? include ("".$_SERVER['DOCUMENT_ROOT']."/phprentals/includes/config.php"); $selectquery = "SELECT DISTINCT state FROM listings"; //echo "$selectquery"; $result = mysql_query($selectquery) or die ("Query failed"); while ($row = mysql_fetch_array($result)) { $state=urlencode($row["state"]); echo "<a href=\"/phprentals/html/link.php?state=$state\">".$row["state"]."</a><BR>"; } ?> </FONT></P><BR> </TD> </TR> Link to comment https://forums.phpfreaks.com/topic/41716-how-can-i-make-this-work/ Share on other sites More sharing options...
effigy Posted March 8, 2007 Share Posted March 8, 2007 You can use % (modulus) or a slice/splice of an array: <pre> <?php $letters = range(1, 100); $counter = 1; echo '<table border="1"><tr>'; foreach ($letters as $letter) { echo "<td>$letter</td>"; if ($counter && ! ($counter % 10)) { echo '</tr><tr>'; } ++$counter; } echo '</tr></table>'; ?> </pre> Link to comment https://forums.phpfreaks.com/topic/41716-how-can-i-make-this-work/#findComment-202291 Share on other sites More sharing options...
CoffeeAddict Posted March 8, 2007 Author Share Posted March 8, 2007 Thank you very much for the reply. Where exactly would I place that into the code I posted? Link to comment https://forums.phpfreaks.com/topic/41716-how-can-i-make-this-work/#findComment-202306 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.