Jump to content

[SOLVED] Multiple display columns data from db


forumnz

Recommended Posts

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.

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>";
?>

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.