diff options
Diffstat (limited to 'public')
-rw-r--r-- | public/index.php | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/public/index.php b/public/index.php index cf8e7d1..0fd0ff2 100644 --- a/public/index.php +++ b/public/index.php @@ -1,5 +1,16 @@ <!DOCTYPE html> <?php require "../lib/db.php"; ?> +<?php +function promobuff2str($price_buff, $count_buff) { + if ($count_buff == 1) return ((1-$price_buff)*100)."% korting"; + if ($count_buff <= 4) { + for ($i = $count_buff-1; $i > 0; $i--) + if (abs((($i/$count_buff)-$price_buff)/$price_buff) < 0.001) + return $i."+".($count_buff - $i)." gratis"; + } + return ((1-$price_buff)*100)."% korting per ".$count_buff."-pack"; +} +?> <html> <head> <?php include 'head.php' ?> @@ -13,9 +24,11 @@ <h1>hier zijn de aanbiedingen</h1> <ul> <?php - $res = $cursor->query("select product.id, product.name as name from promotion join product on product.id = promotion.product"); + $res = $cursor->query("select product.id, product.name as name, promotion.count_buff, promotion.price_buff from promotion join product on product.id = promotion.product"); while ($product = $res->fetch_object()) { - echo "<li><a href=\"/product.php?id=$product->id\">$product->name</a></li>"; + echo "<li><a href=\"/product.php?id=$product->id\">$product->name</a>: "; + echo promobuff2str($product->price_buff, $product->count_buff); + echo "</li>"; } ?> </ul> |