php - Table won't populate with data -


i've been new programming , been working phpmyadmin on localhost. making simple table on webpage display data. problem everytime load page displays table , not table load up. here code:

<?php require('../model/database.php'); require('../model/product_db.php');  $products = get_products();   if (isset($_post['action'])) {     $action = $_post['action']; } else if (isset($_get['action'])) {     $action = $_get['action']; } else {     $action = 'under_construction'; }     // display product list     include('view-productlist.php');  ?>      

this view-productlist.php:

<?php include '../view/header.php'; ?>   <div id="main">      <h1>product list</h1>       <div id="content">         <!-- display table of products -->         <h2><?php echo $name; ?></h2>         <table>             <tr>                 <th>code</th>                 <th>name</th>                 <th class="right">version</th>                 <th>&nbsp;</th>             </tr>              <?php foreach ($products $product) : ?>             <tr>                 <td><?php echo $product['productcode']; ?></td>                 <td><?php echo $product['name']; ?></td>                 <td class="right"><?php echo $product['version']; ?></td>                 <td><form action="." method="post">                     <input type="hidden" name="action"                            value="delete_product" />                     <input type="hidden" name="product_id"                            value="<?php echo $product['productid']; ?>" />                     <input type="hidden" name="category_id"                            value="<?php echo $product['categoryid']; ?>" />                     <input type="submit" value="delete" />                 </form></td>             </tr>             <?php endforeach; ?>         </table>         <p><a href="?action=show_add_form">add product</a></p>     </div>  </div> <?php include '../view/footer.php'; ?> 

query page:

<?php function get_products() {     global $db;     $query = 'select * products               order productid';     $products = $db->query($query);     return $products; }  function get_products_by_category($category_id) {     global $db;     $query = "select * products               products.categoryid = '$category_id'               order productid";     $products = $db->query($query);     return $products; }  function get_product($product_id) {     global $db;     $query = "select * products               productid = '$product_id'";     $product = $db->query($query);     $product = $product->fetch();     return $product; }  function delete_product($product_id) {     global $db;     $query = "delete products               productid = '$product_id'";     $db->exec($query); } 

product_db.php should not commented out 1 - assuming file holds "query page:" contents.

$products = get_products();  

should come after include.

and loop needs fetch result , not product resource:

<?php foreach ($products->fetch() $product) : ?> 

assuming fetch() relevant type of resource since can't see db class.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -