Page 1 of 1
Printing Table with PHP
Posted: Fri Apr 17, 2009 5:39 pm
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
Re: Printing Table with PHP
Posted: Fri Apr 17, 2009 6:46 pm
by php_east
Code: Select all
echo "<table>";
echo "<tr>";
echo "<td width=400>".$row['title']." Seller: ".$row['name']."</td>";
echo("</tr>");
Re: Printing Table with PHP
Posted: Fri Apr 17, 2009 6:56 pm
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.
Re: Printing Table with PHP
Posted: Fri Apr 17, 2009 6:59 pm
by php_east
that would be a problem before this part, inside or after your database.
Re: Printing Table with PHP
Posted: Fri Apr 17, 2009 7:01 pm
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
Re: Printing Table with PHP
Posted: Sat Apr 18, 2009 4:27 am
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.
Re: Printing Table with PHP
Posted: Sat Apr 18, 2009 12:50 pm
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.
Re: Printing Table with PHP
Posted: Wed Apr 22, 2009 9:01 pm
by Foxy999
I am still having trouble with values from the database not showing up in the tables, please help.
Note: See above post.
Re: Printing Table with PHP
Posted: Thu Apr 23, 2009 11:42 am
by Foxy999
Nevermind, I got it to work.