Jump to content

PHP data in HTML Table


duttydea

Recommended Posts

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

<?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>

<?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>

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.