From 569d61381723eea60188e00d6133fddcaee37ef8 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Thu, 18 May 2023 18:17:41 +0200 Subject: display and filter categories on products page --- public/products.php | 88 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 70 insertions(+), 18 deletions(-) (limited to 'public/products.php') diff --git a/public/products.php b/public/products.php index da337ad..ce0ada5 100644 --- a/public/products.php +++ b/public/products.php @@ -13,6 +13,34 @@ function product_template($product) { EOF; } ?> + +query("select id, name, parent from category where parent is null"); + } else { + $statement = $cursor->prepare("select id, name, parent from category where parent = ?"); + $statement->bind_param("i", $id); + $statement->execute(); + $res = $statement->get_result(); + } + if (!mysqli_num_rows($res)) return; + echo '
'; + $categories = $res->fetch_all(MYSQLI_ASSOC); + foreach ($categories as $category) { + // php is een hele mooie programmeertaal die heel fijn werkt + echo ""; + echo $category["name"]; + echo ""; + categories_recursive($category["id"]); + } + echo '
'; +} ?> @@ -22,25 +50,49 @@ EOF;
-

lijst met producten:

- -
- -
-
- -
+
+
+

Filters

+

Categorieën

+
+ Reset +
- EOF; - } while (false); ?> -
- query("select id, image, price, name from webs.product"); - while ($product = $res->fetch_object()) product_template($product); - ?> +
+
+ Producten"; + if ($id !== null) echo " in categorie $id"; + echo ""; + ?> + +
+ +
+
+ +
+
+ EOF; + } while (false); ?> +
+ query("select id, image, price, name from webs.product"); + } else { + $statement = $cursor->prepare("select id, image, price, name from webs.product where category = ?"); + $statement->bind_param("i", $id); + $statement->execute(); + $res = $statement->get_result(); + } + while ($product = $res->fetch_object()) product_template($product); + ?> +
+
-- cgit v1.2.3