Jump to content

How would I display results in multi-column table?


simcoweb

Recommended Posts

I'm creating a classifieds system and need to list the categories in  say a 3 column layout. I know how to 'while' loop through an array to display rows. In this case, however, I need to display the categories in a table where each cell is a separate item instead of the row constituting a record/row from the database.

 

Should look like:

 

Category 1 Category 2 Category 3

Category 4Category 5Category 6

Category 7Category 8Category 9

 

etc. There would also be some sub-cats displayed in each cell as well.

 

What i'm looking for is the coding that would create a table row when needed and how it would place the results starting left-to-right for as many cells/rows as needed.

Quick write up:

 

$totalColumns = 5;
$i = 1;
echo '<table border="1">';
for ($b=0;$b<15;$b++)
{
if ($i == 1)
	echo '<tr>';

echo '<td>';
echo 'item' ,$i;
echo '</td>';

if ($i == $totalColumns)
	{
	echo '</tr>';
	$i = 0;
	}
$i++;
}

echo '</table>';

Xinil, thanks for that example. I can understand it as it applies to incrementing the number of cells needed per column. I see you have, in your example, $totalColumns set to 5. I'd probably change that to 3 and I don't see anywhere else in your example where that would affect anything.

 

Ted, i'm looking at whatever works best. If I made the columns a fixed number then i'd like to see the code snippet that would display it that way. Could you please?

 

Thanks to both of you :)

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.