Hello, I am trying to get the results from a mysql database and display them into a table. I will have many rows, but I only want 3 columns. I want each row of the table to display as such:

Column 1       Column 2       Column 3
Result 1       Result 2       Result 3
Result 4       Result 5       Result 6
Result 7       Result 8       Result 9

The problem is, the code I have does not do this, here is my code below, please help me do what I have asked above, please?

<table id="pr" width="100%" border="1" cellspacing="0" cellpadding="0">
<?php
$result = mysql_query("SELECT * FROM products ") 
 or die(mysql_error());
while($row = mysql_fetch_array( $result )) {
  $productNo = $row['productNo'];
  $productCode = $row['productCode'];
  $name = $row['name'];
  $desc = $row['desc'];
  $image = $row['image'];
?>
  <tr>
  <td align="center" valign="top">
   Product No: <?php echo $productNo; ?><br />
  <?php echo $productNo; ?><br />
  <img src="images/merch/<?php echo $image; ?>" width="216" height="170" /><br />
  <?php echo $desc; ?>
  </td>
  <td align="center" valign="top">
   Product No: <?php echo $productNo; ?><br />
  <?php echo $productNo; ?><br />
  <img src="images/merch/<?php echo $image; ?>" width="216" height="170" /><br />
  <?php echo $desc; ?>
  </td>
  <td align="center" valign="top">
  Product No: <?php echo $productNo; ?><br />
  <?php echo $productNo; ?><br />
  <img src="images/merch/<?php echo $image; ?>" width="216" height="170" /><br />
  <?php echo $desc; ?>
  </td>
  </tr>
<?php
}
?>
</table>

Thanks!

    Before going any further, did you consider letting go of the table, and using a fluid design, where you create floating elements which will build up your display of products?

    In any case:

    
    <?php
    $result = mysql_query("SELECT * FROM products ")
      or die(mysql_error());
    
    $i=1;
    
    while($row = mysql_fetch_array( $result )) 
      {
      if($i % 3 == 0)
        {
        if($i == 1)
          {
          echo "<tr>";
          }
        else
          {
          echo "</tr><tr>";
          }
        }
      }
    
      echo"
      <td align=\"center\" valign=\"top\">
       Product No: ".$row['productNo']."<br />
       ".$row['productNo']."<br />
      <img src=\"images/merch/".$row['image']."\" width=\"216\" height=\"170\" /><br />
      ".$row['desc']."
      </td>";
      }
    
      Write a Reply...