Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I set up 2 colums so that 2

Status
Not open for further replies.

cs7536

Programmer
Joined
Apr 20, 2003
Messages
130
Location
US
How do I set up 2 colums so that 2 articles can display on each row so if I have 8 articles it will display as followed:

article article
article article
article article
article article

does any body know how to get this done in php?

Thanks
Max

Nothing is hard when you realy want to learn it.

Max
 
just need to get 2 items per colum..


Thanks for those of you that can help with this.

Max

Nothing is hard when you realy want to learn it.

Max
 
Use a counter.

Output your data formatted inside table tags. Output each table column, increment the counter and check it against the number of columns you wish to output. If you've already output the requisite number of columns, start a new table row and reset your counter to 0.

Want the best answers? Ask the best questions: TANSTAAFL!
 
Hello sleipnir214 can you reffer me to a portion of the php manual for this?

I have learned so much thanks to your forum, if no one has thanked you I would like to be one of the first to say thanks for posting this forum rather you know it or not you are halping alot of people.

Great work
Max

Nothing is hard when you realy want to learn it.

Max
 
Can you please guide me with an example?
that would be appreciated, I don't need the answer just a start to run with..


Thanks
Max

Nothing is hard when you realy want to learn it.

Max
 
Try something like this:

Code:
<?php
$number_of_columns = 2;

$data = array ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n');

print '<html><body><table border=1>';

$column_counter = 0;

foreach ($data as $datum)
{
   if ($column_counter == 0)
   {
      print '<tr>';
   }

   print '<td>' . $datum . '</td>';
   $column_counter++;

   if ($column_counter == $number_of_columns)
   {
     print '</tr>';
     $column_counter = 0;
   }
}

/*
   This part of the code just &quot;cleans up&quot; the table, outputting
   any missing columns
*/
if ($column_counter != 0)
{
   while ($column_counter < $number_of_columns)
   {
      print '<td>&nbsp;</td>';
      $column_counter++;
   }
   print '</tr>';
}
print '</table></body></html>';
?>code]

The code is a more general solution to the problem.  The variable $number_of_columns will specify how many columns the table will have.

[i]Want the best answers?  Ask the best questions:[/i] [URL unfurl="true"]http://www.catb.org/~esr/faqs/smart-questions.html[/URL]
TANSTAAFL!
 
Thanks alot for the tutorial I raly appreciate you alot for this..

Max

Nothing is hard when you realy want to learn it.

Max
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top