Printing Table with PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Foxy999
Forum Commoner
Posts: 45
Joined: Sat Mar 21, 2009 11:50 am

Printing Table with PHP

Post by Foxy999 »

I need help creating a table with the PHP function echo, and printing variables in the same statement.

Here's what I have:
echo("<tabel>");
echo("<tr>");
echo("<td WIDTH=400>$row['title'] Seller: $row['name']</td>");
echo("</tr>");

I have tried several different ways to print this, so this is my original code.

Foxy
User avatar
php_east
Forum Contributor
Posts: 453
Joined: Sun Feb 22, 2009 1:31 pm
Location: Far Far East.

Re: Printing Table with PHP

Post by php_east »

Code: Select all

 
echo "<table>";
echo "<tr>";
echo "<td width=400>".$row['title']." Seller: ".$row['name']."</td>";
echo("</tr>");
 
Foxy999
Forum Commoner
Posts: 45
Joined: Sat Mar 21, 2009 11:50 am

Re: Printing Table with PHP

Post by Foxy999 »

php_east wrote:

Code: Select all

 
echo "<table>";
echo "<tr>";
echo "<td width=400>".$row['title']." Seller: ".$row['name']."</td>";
echo("</tr>");
 
That worked, but it isn't printing the database values on the page, in the array $row.
User avatar
php_east
Forum Contributor
Posts: 453
Joined: Sun Feb 22, 2009 1:31 pm
Location: Far Far East.

Re: Printing Table with PHP

Post by php_east »

that would be a problem before this part, inside or after your database.
Foxy999
Forum Commoner
Posts: 45
Joined: Sat Mar 21, 2009 11:50 am

Re: Printing Table with PHP

Post by Foxy999 »

This is what I have:

$con = mysql_connect("localhost", "yourcol1_default", "default");
if(!$con)
{
die('Cannot connect: ' .mysql_error());
}
mysql_select_db("yourcol1_ITEM", $con);

$query = "SELECT * FROM SELL";
$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result))

It was printing the values of the database before I decided to create tables.

Foxy
User avatar
php_east
Forum Contributor
Posts: 453
Joined: Sun Feb 22, 2009 1:31 pm
Location: Far Far East.

Re: Printing Table with PHP

Post by php_east »

Foxy999 wrote:It was printing the values of the database before I decided to create tables.Foxy
which means at this point, before entry into the table, you would have
$row values. but when you entered the table, you did not repeat this, hence you will not have any $rows.

Code: Select all

while($row = mysql_fetch_array($result))
{
 TABLE SHOULD BE HERE ( you may also wish to confirm first you have $row by printing just $row. )
 }
 
also, please use the codes tag provided in this forum, it makes reading codes a lot easier.
Foxy999
Forum Commoner
Posts: 45
Joined: Sat Mar 21, 2009 11:50 am

Re: Printing Table with PHP

Post by Foxy999 »

php_east wrote:
Foxy999 wrote:It was printing the values of the database before I decided to create tables.Foxy
which means at this point, before entry into the table, you would have
$row values. but when you entered the table, you did not repeat this, hence you will not have any $rows.

Code: Select all

while($row = mysql_fetch_array($result))
{
 TABLE SHOULD BE HERE ( you may also wish to confirm first you have $row by printing just $row. )
 }
 
also, please use the codes tag provided in this forum, it makes reading codes a lot easier.
I am not sure if I understand; there are values in the database so something should show up. My while loop is working and it is printing the table and some words as many times as there are data in the database.
Foxy999
Forum Commoner
Posts: 45
Joined: Sat Mar 21, 2009 11:50 am

Re: Printing Table with PHP

Post by Foxy999 »

I am still having trouble with values from the database not showing up in the tables, please help.

Note: See above post.
Foxy999
Forum Commoner
Posts: 45
Joined: Sat Mar 21, 2009 11:50 am

Re: Printing Table with PHP

Post by Foxy999 »

Nevermind, I got it to work.
Post Reply