diff options
author | lonkaars <loek@pipeframe.xyz> | 2023-05-08 13:20:14 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2023-05-08 13:20:14 +0200 |
commit | 847347fb5511f6c526e41e0e5963e6d4f3882e58 (patch) | |
tree | 7559f1dcb2b55871b17eed1d7081b10d97026108 | |
parent | 14997bb700d5bc30d69a48294ae26a7e566939c5 (diff) |
WIP show products in database
-rw-r--r-- | db/init.sql | 2 | ||||
-rw-r--r-- | public/db.php | 1 | ||||
-rw-r--r-- | public/products.php | 36 |
3 files changed, 18 insertions, 21 deletions
diff --git a/db/init.sql b/db/init.sql index c842e52..872d456 100644 --- a/db/init.sql +++ b/db/init.sql @@ -10,7 +10,7 @@ create table if not exists webs.product ( `ID` int not null auto_increment, `name` varchar(255) not null, `price` decimal(5, 2) not null, - `image` mediumblob null default null, + `image_path` varchar(255) not null default "img/placeholder.png", `category` int not null, primary key (`ID`), constraint `product_category_fk` diff --git a/public/db.php b/public/db.php new file mode 100644 index 0000000..6d158b7 --- /dev/null +++ b/public/db.php @@ -0,0 +1 @@ +<?php $cursor = new mysqli("localhost", "loek", "", "webs"); ?> diff --git a/public/products.php b/public/products.php index 077702a..e9c7cdf 100644 --- a/public/products.php +++ b/public/products.php @@ -1,4 +1,16 @@ <!DOCTYPE html> +<?php require "db.php"; ?> +<?php +function product_template($product) { + echo <<<"EOF" + <a href="/product.php?id=$product->id" class="product nolinkstyle"> + <img src="$product->img" alt=""> + <span class="price">$product->price</span> + <span class="name">$product->name</span> + </a> +EOF; +} +?> <html> <head> <?php include 'head.php' ?> @@ -10,26 +22,10 @@ <div class="main limwidth"> <h2>lijst met producten:</h2> <div class="products"> - <a href="/product.php?id=123" class="product nolinkstyle"> - <img src="img/placeholder.png" alt=""> - <span class="price">3,45</span> - <span class="name">courgette</span> - </a> - <a href="/product.php?id=123" class="product nolinkstyle"> - <img src="img/placeholder.png" alt=""> - <span class="price">3,45</span> - <span class="name">courgette</span> - </a> - <a href="/product.php?id=123" class="product nolinkstyle"> - <img src="img/placeholder.png" alt=""> - <span class="price">3,45</span> - <span class="name">courgette</span> - </a> - <a href="/product.php?id=123" class="product nolinkstyle"> - <img src="img/placeholder.png" alt=""> - <span class="price">3,45</span> - <span class="name">courgette</span> - </a> + <?php + $res = $cursor->query("select ID as id, image_path as img, price, name from webs.product"); + while ($product = $res->fetch_object()) product_template($product); + ?> </div> </div> <?php include 'footer.php' ?> |