Guest User

Untitled

a guest
Mar 20th, 2019
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.28 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.     <head> 
  4.     <body style="background-color:grey;text-align:center">
  5.         <meta charset="utf-8">
  6.         <title>Z's Jewelers</title>
  7.         <link rel="stylesheet" href="productList.css">
  8.         </head>
  9.         <body>
  10.           <h1>Z's Jewelers</h1>
  11.             <ul class="product_list">
  12.               <h2>Product List</h2>
  13.               <?php
  14.                     $products = array();
  15.                    
  16.                     $servername = "localhost:3306";
  17.                     $username = "root";
  18.                     $password = "";
  19.                     $dbname = "ourdatabase";
  20.                    
  21.                     $conn = mysqli_connect($servername, $username, $password, $dbname);
  22.  
  23.                     if (!$conn) {
  24.                         die("Connection failed: " . mysqli_connect_error());
  25.                    
  26.                     } else {
  27.                         echo "0 results";
  28.                     }
  29.                    
  30.                     $sql = "SELECT productID, title, description, image, stock, price FROM PRODUCT";
  31.                     $result = mysqli_query($conn, $sql);
  32.                     if (mysqli_num_rows($result) > 0) {
  33.                         while($row = mysqli_fetch_assoc($result)) {
  34.                             $product = [];
  35.                             $product['name'] = $row['title'];
  36.                             $product['id'] = $row['productID'];
  37.                             $product['image'] = $row['image'];
  38.                             $product['description'] = $row['description'];
  39.                             $product['stock'] = $row['stock'];
  40.                             $product['price'] = $row['price'];
  41.                             //$productID = $row['productID'];
  42.                             //$title= $row['title'];
  43.                             //$description = $row['description'];
  44.                             //$image = $row['image'];
  45.                             //$stock = $row['stock'];
  46.                             //$price = $row['price'];
  47.                             //$product = array($productID, $description, $image, $stock, $price);
  48.                             array_push($products, $product);
  49.                         }
  50.                     }
  51.                     mysqli_close($conn);
  52.                 ?>
  53.                 <?php
  54.                     foreach($products as $product) {
  55.                     $href="shoppingcart.php?productid=" . $product['id']
  56.                         . "&productname=" . $product['name']
  57.                         . "&price=" . $product['price']
  58.                         . "&quantity=1";    
  59.                         echo '<li>
  60.                         <img src=" ' . $product['image'] . ' " alt=" ' .$product['alt'] . ' ">
  61.                         <div class="product_information">
  62.                             <h4>' . $product['name'] . '</h4>
  63.                             <span>' . $product['price'] . '</span>
  64.                         </div>
  65.                         <div class="product_description">
  66.                             <p>' . $product['description'] . '</p>
  67.                             <a href=" ' . $href .' "class="add_to_cart">Add to cart</a>
  68.                         </div>
  69.                         </li>';
  70.                     }
  71.                    
  72.                 ?>             
  73.         </body>
  74.        
  75. </html>
Add Comment
Please, Sign In to add comment