Web Hosting Talk







View Full Version : code snippet - building vertical columns from a mysql result


Philco
03-17-2006, 06:24 AM
$result = mysql_query("SELECT * FROM cities ORDER BY city_name") or die ("Failed.".mysql_error());
$num_rows = mysql_num_rows($result);
$x = 0;
$num_cols = 4;

print '
<TABLE CELLPADDING="0" CELLSPACING="0" BORDER="0" WIDTH="100%">
<TR>
<TD VALIGN="TOP">';
while($row = mysql_fetch_array($result)) {

print $row['city_name']. '<BR>';

$x++;

if ($x == ceil($num_rows / $num_cols)) {

print '
</TD>
<TD VALIGN="TOP">';

$x = 0;

}

}
print '
</TD>
</TR>
</TABLE>';
$num_cols is the number of columns you want....

Philco

welshboy
09-16-2006, 03:12 PM
thanks ive been loking for something like this for my uncles site, hel be happy in the morning when i give him a link to the site