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.

Link to comment
Share on other sites

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>';

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.