The way I do this is a very simple bit of code:

Outside the "while" statement, add the line:

$column = 1;  

Then, inside the "while" statement, take the <tr></tr> statements out and 
instead do something like this:

     $column++;  
       
     if ($column > 3)  
     {  
          echo "</tr><tr>";  
          $column = 1;  
     }  

This will render a new table row every time the counter reaches 3. You can 
change that number to make as many cells as you want before rendering a new 
table row.

You will probably want to take the <table></table> out of the "while" 
statement too, unless you really do want to make a new table for every record 
returned.

Hope that helps.

Good luck,
Dan

> Hi everyone!
> 
> Is there a good tutorial on how to write html tables in PHP?
> 
> In my last post "Not displaying all records" I have the items 
> displayig all the contents of the table but they are in descending order.
> like this
> item 1
> item 2
> 
> Here is the code I am using
> 
> $query = "SELECT id, name, image, quantity FROM {$config["prefix"]}_my_items
> WHERE uid={$session["uid"]} ORDER BY id";
> $ret = mysql_query($query);
> while($row = mysql_fetch_array($ret)){
> $image = $row['image'];
> $name = $row['name'];
> $quantity = $row['quantity'];
> 
> $display_block ="<img src=$image><CENTER><br>$name<BR>$quantity</CENTER>";
> echo "<table><tr><td>$display_block</td></tr></table>";
> echo"";
> }
> 
> I have already tried this
> 
> $display_block ="<img src=$image><CENTER><br>$name<BR>$quantity</CENTER>";
> echo
> "<table><tr><td>$display_block</td><td>$display_block</td></tr></table>";
> echo"";
> 
> But it displays 2 sets of all items still in descending order beside 
> each other:
> 
> item 1     item 1
> item 2     item 2
> 
> What I wnat is to display them
> 
> item 1     item 2     item 3
> 
> Is there a way to do this?
> 
> Thanks
> Jennifer
> 
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.344 / Virus Database: 191 - Release Date: 4/2/2002
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
------- End of Forwarded Message -------




-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to