Jump to content

How can I make this work?


CoffeeAddict

Recommended Posts

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

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.