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!
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi
I’m new to php, I’m just trying to get a result from a mysql query into a html table
When I run this script it doesn’t show up a result, not even an error just a blank page, can some one let me know where I’m going wrong?
Thanks
Clint
<?PHP
//connect to the mysql database
$connection=mysql_connect("localhost","computer_test","test1");
mysql_select_db("computer_price",$connection);
$query="SELECT p.PartNumber, p.Description, (p.IncTax*1.3) AS Price FROM `price list` p";
$data_resource=mysql_query($query,$connection);
//Defining HTML table
$table="<table cellspacing=0 cellpadding=0 width=400>";
while ($row = mysql_fetch_array($data_resource)) {
$table.="<tr>";
$table.="<td>".$row['p.PartNumber']."</td>";
$table.="<td>".$row['p.Descripton']."</td>";
$table.="</tr>";
}
//Closing HTML table
$table.="</table>";
//Displying table and closing mysql database if not need
echo $table;
mysql_close();
?>
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Can you do a right click -> View Source on the blank page, and post the result? Could be that PHP is throwing some error that you can only see in the source of the page.
Could also be that you are getting some sort of database error. You should really have some error handling functionality in your script - it takes 2 minutes extra to write the code, and saves hours and hours of time.
Be aware that this will only work for non-critical errors. If your page is still blank after adding this piece of code, you will need to scan your code line by line looking for a missing semicolon or some other parse error type (the usual suspects).