> I've got the following situation: I have a list of items i want
placed
> in side-by-side columns in a table like this:
>
> name name name name
> name name name name
> name name name name
> name name name name
>
> and so on. How can I do it? Name is a string in the database.
You can try something like this:
<?
$Count = 1;
$Num_Across = 4;
$Width = floor(100 / $Num_Across);
//start table and first row
echo "<table width='100%'>\n";
echo "<tr>\n";
while($row = MySQL_fetch_array($result))
{
//create first cell
echo "<td width='$width'>".$row['name']."</td>\n";
//keep a count so you know when to start a new row
if($count % $Num_Across == 0)
{ $retval .= "</tr><tr>\n"; }
$count++;
}
//this will finish the table, i.e. if you only have one
//name on last row, this will fill in the remaining table
//cells
$left = $Num_Across - (--$count % $Num_Across);
for($x=0;$x<$left;$x++)
{ echo "<td> </td>\n"; }
That last part isn't tested. I used a different method, but hopefully
this gives you an idea.
---John Holmes...
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php