Jump to content


Photo

Two colums per row in html table


  • Please log in to reply
2 replies to this topic

#1 t_machine

t_machine
  • Members
  • PipPipPip
  • Advanced Member
  • 104 posts

Posted 04 March 2006 - 06:33 PM

hi, I would like to display my database result in a table but only two per row. I am using a while loop so my query looks like the following

while($row ........

I would like it to work like this

<tr>
<td>item 1 </td> <td> item 2</td></tr>
<tr>
<td>item 3</td> <td> item 4</td></tr>

See how after two colums it starts another row to display the next two results? How can this be done. Thanks :)




#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 04 March 2006 - 06:53 PM

$itemsPerRow = 2;
$count = 0;
while($row = mysql_fetch_array($sql)) {
  if ($count % $itemsPerRow == 0)
    echo "<tr>\n";
  $count++;
  echo "<td>$row[whatever]</td>\n";
  if ($count % $itemsPerRow == 0)
    echo "</tr>\n";
}

hope this helps!
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 t_machine

t_machine
  • Members
  • PipPipPip
  • Advanced Member
  • 104 posts

Posted 04 March 2006 - 07:05 PM

Thank you very much :) This works perfectly




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users