Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <body style="background-color:grey;text-align:center">
- <meta charset="utf-8">
- <title>Z's Jewelers</title>
- <link rel="stylesheet" href="productList.css">
- </head>
- <body>
- <h1>Z's Jewelers</h1>
- <ul class="product_list">
- <h2>Product List</h2>
- <?php
- $products = array();
- $servername = "localhost:3306";
- $username = "root";
- $password = "";
- $dbname = "ourdatabase";
- $conn = mysqli_connect($servername, $username, $password, $dbname);
- if (!$conn) {
- die("Connection failed: " . mysqli_connect_error());
- } else {
- echo "0 results";
- }
- $sql = "SELECT productID, title, description, image, stock, price FROM PRODUCT";
- $result = mysqli_query($conn, $sql);
- if (mysqli_num_rows($result) > 0) {
- while($row = mysqli_fetch_assoc($result)) {
- $product = [];
- $product['name'] = $row['title'];
- $product['id'] = $row['productID'];
- $product['image'] = $row['image'];
- $product['description'] = $row['description'];
- $product['stock'] = $row['stock'];
- $product['price'] = $row['price'];
- //$productID = $row['productID'];
- //$title= $row['title'];
- //$description = $row['description'];
- //$image = $row['image'];
- //$stock = $row['stock'];
- //$price = $row['price'];
- //$product = array($productID, $description, $image, $stock, $price);
- array_push($products, $product);
- }
- }
- mysqli_close($conn);
- ?>
- <?php
- foreach($products as $product) {
- $href="shoppingcart.php?productid=" . $product['id']
- . "&productname=" . $product['name']
- . "&price=" . $product['price']
- . "&quantity=1";
- echo '<li>
- <img src=" ' . $product['image'] . ' " alt=" ' .$product['alt'] . ' ">
- <div class="product_information">
- <h4>' . $product['name'] . '</h4>
- <span>' . $product['price'] . '</span>
- </div>
- <div class="product_description">
- <p>' . $product['description'] . '</p>
- <a href=" ' . $href .' "class="add_to_cart">Add to cart</a>
- </div>
- </li>';
- }
- ?>
- </body>
- </html>
Add Comment
Please, Sign In to add comment