duttydea Posted March 10, 2008 Share Posted March 10, 2008 The following code fails to display the data in the html table. I have tried to change a database field to a name that is not present in the database table No PHP errors are shown, i dont even think the script is even connecting to the database.. What am i doing wrong? <?php //--------------- Connection Script ----------------------------\\ $username = "********"; $password = "********"; $hostname = "********"; $dbh = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); //------------------- Select Database --------------------------\\ $selected = mysql_select_db("dutty_dp",$dbh) or die("Could not select first_test"); ?> </head> <body> <? $query = "SELECT `Product_picurl`, `Product_Name`, `Product_Description`, `Product_price`, `Product_Category`, `Product_Pdf`, `Product_Cart`, `Product_Features`, `Product_subcat`, `Key` FROM `prod_listing` where `Product_subcat` = 'Absorption Panels'"; ?> <table width="42%" cellpadding="1" cellspacing="0"> <? while ($row=mysql_fetch_array($query)) { ?> <tr> <td height="16" colspan="2" valign="top"><div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"> <?php echo $row["Product_Name"];?> / Product ID <?php echo $row["Product_Id"] ;?></font></div></td> </tr> <tr> <td width="19%" height="108"><div align="justify"><?php echo $row["Product_picurl"];?> <p align="center"> £<?php echo $row["Product_price"];?></div></td> <td width="81%" valign="top"><?php echo $row["Product_Description"];?></td> </tr> <tr> <td height="25" colspan=2><p align="center"><a href="#">Add to Cart</a></p> </td> </tr> <? } //end of loop ?> </table> Can some one please help? Thanks in advance Link to comment https://forums.phpfreaks.com/topic/95503-php-data-in-html-table/ Share on other sites More sharing options...
frijole Posted March 10, 2008 Share Posted March 10, 2008 <?php //--------------- Connection Script ----------------------------\\ $username = "********"; $password = "********"; $hostname = "********"; $dbh = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); //------------------- Select Database --------------------------\\ $selected = mysql_select_db("dutty_dp",$dbh) or die("Could not select first_test"); ?> </head> <body> <?php // <------------------------------In your code there is no "php" here to tell the browser it is php and not HTML $query = "SELECT `Product_picurl`, `Product_Name`, `Product_Description`, `Product_price`, `Product_Category`, `Product_Pdf`, `Product_Cart`, `Product_Features`, `Product_subcat`, `Key` FROM `prod_listing` where `Product_subcat` = 'Absorption Panels'"; ?> <table width="42%" cellpadding="1" cellspacing="0"> <? while ($row=mysql_fetch_array($query)) { ?> <tr> <td height="16" colspan="2" valign="top"><div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"> <?php echo $row["Product_Name"];?> / Product ID <?php echo $row["Product_Id"] ;?></font></div></td> </tr> <tr> <td width="19%" height="108"><div align="justify"><?php echo $row["Product_picurl"];?> <p align="center"> £<?php echo $row["Product_price"];?></div></td> <td width="81%" valign="top"><?php echo $row["Product_Description"];?></td> </tr> <tr> <td height="25" colspan=2><p align="center"><a href="#">Add to Cart</a></p> </td> </tr> <? } //end of loop ?> </table> Link to comment https://forums.phpfreaks.com/topic/95503-php-data-in-html-table/#findComment-488864 Share on other sites More sharing options...
frijole Posted March 10, 2008 Share Posted March 10, 2008 I just saw a few more places that you forgot to use <?php, just <? will not work. <?php echo '<p>Hello World</p>'; ?> not <? echo '<p>Hello World</p>'; ?> If you fix all of those you should be on your way. Link to comment https://forums.phpfreaks.com/topic/95503-php-data-in-html-table/#findComment-488871 Share on other sites More sharing options...
dotBz Posted March 10, 2008 Share Posted March 10, 2008 if i read it correctly, i guess you forgot mysql_query() Link to comment https://forums.phpfreaks.com/topic/95503-php-data-in-html-table/#findComment-488873 Share on other sites More sharing options...
duttydea Posted March 10, 2008 Author Share Posted March 10, 2008 if i read it correctly, i guess you forgot mysql_query() Im a Newcommer to PHP.. The Code was provided by a user on another forum. As a newbie i not sure how to include the mysql_query() in this script. Thanks in advance Link to comment https://forums.phpfreaks.com/topic/95503-php-data-in-html-table/#findComment-488878 Share on other sites More sharing options...
Naez Posted March 10, 2008 Share Posted March 10, 2008 <?php //--------------- Connection Script ----------------------------\\ $username = "********"; $password = "********"; $hostname = "********"; $dbh = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); //------------------- Select Database --------------------------\\ $selected = mysql_select_db("dutty_dp",$dbh) or die("Could not select first_test"); ?> </head> <body> <? $query = "SELECT `Product_picurl`, `Product_Name`, `Product_Description`, `Product_price`, `Product_Category`, `Product_Pdf`, `Product_Cart`, `Product_Features`, `Product_subcat`, `Key` FROM `prod_listing` where `Product_subcat` = 'Absorption Panels'"; //////////////////////////////////////////////// $result = mysql_query($query); ////////////////////////////////////// ?> <table width="42%" cellpadding="1" cellspacing="0"> <?php //////////////////////////////////////////////// while ($row=mysql_fetch_array($result) { ?> // snip } </table> Link to comment https://forums.phpfreaks.com/topic/95503-php-data-in-html-table/#findComment-488880 Share on other sites More sharing options...
frijole Posted March 10, 2008 Share Posted March 10, 2008 As far as I can tell, this should work: <?php //--------------- Connection Script ----------------------------\\ $username = "********"; $password = "********"; $hostname = "********"; $dbh = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); //------------------- Select Database --------------------------\\ $selected = mysql_select_db("dutty_dp",$dbh) or die("Could not select first_test"); ?> </head> <body> <?php // <------------------------------In your code there is no "php" here to tell the browser it is php and not HTML $query = "SELECT `Product_picurl`, `Product_Name`, `Product_Description`, `Product_price`, `Product_Category`, `Product_Pdf`, `Product_Cart`, `Product_Features`, `Product_subcat`, `Key` FROM `prod_listing` where `Product_subcat` = 'Absorption Panels'"; $result = mysql_query($query); ?> <table width="42%" cellpadding="1" cellspacing="0"> <?php while ($row=mysql_fetch_array($result)) { ?> <tr> <td height="16" colspan="2" valign="top"><div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"> <?php echo $row["Product_Name"];?> / Product ID <?php echo $row["Product_Id"] ;?></font></div></td> </tr> <tr> <td width="19%" height="108"><div align="justify"><?php echo $row["Product_picurl"];?> <p align="center"> £<?php echo $row["Product_price"];?></div></td> <td width="81%" valign="top"><?php echo $row["Product_Description"];?></td> </tr> <tr> <td height="25" colspan=2><p align="center"><a href="#">Add to Cart</a></p> </td> </tr> <?php } //end of loop ?> </table> Link to comment https://forums.phpfreaks.com/topic/95503-php-data-in-html-table/#findComment-488881 Share on other sites More sharing options...
duttydea Posted March 10, 2008 Author Share Posted March 10, 2008 Thanks for all your help!!! Link to comment https://forums.phpfreaks.com/topic/95503-php-data-in-html-table/#findComment-488900 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.