Re: HTML tables in PHP
| From: | Steve Cayford | Date: | Wed, 10 Apr 2002 18:48:44 +0000 |
| Subject: | Re: HTML tables in PHP | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-18404@lists.php.net to get a copy of this message | ||
You probably want something more like this (see modified code below).
Note that if you get a lot of records, your html table will keep expanding out to the right. You might want to break it up with rows ... or not, as you like.
There are quite a few places that have intros to php subjects. Check out the list at http://www.php.net/links.php
-Steve
<?php
...
$query = "SELECT id, name, image, quantity FROM {$config["prefix"]}_my_items
WHERE uid={$session["uid"]} ORDER BY id";
$ret = mysql_query($query);
// start your table here, outside the loop
echo "<table><tr>";
while($row = mysql_fetch_array($ret)){
// note: indenting your code in loops makes it much easier to see what's going on :)
$image = $row['image'];
$name = $row['name'];
$quantity = $row['quantity'];
$display_block ="<img src=$image><CENTER><br>$name<BR>$quantity</CENTER>";
// show each record in its own cell here
echo "<td>$display_block</td>";
}
// finish up the table outside the loop
echo "</tr></table>";
?>
On Wednesday, April 10, 2002, at 01:17 PM, Jennifer Downey wrote:
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 2What I wnat is to display themitem 1 item 2 item 3Is 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