diff options
author | lonkaars <loek@pipeframe.xyz> | 2023-06-01 16:30:41 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2023-06-01 16:30:41 +0200 |
commit | 6715936a3b33c14b2d8c581677855bb6c1297940 (patch) | |
tree | 49ef59d2c62f5a7cb6a640c9ac3196c4b22ecd6a /public | |
parent | 879c72e50c172f6e20416dcf06fccdbb59525c7a (diff) |
implement promotion buff coefficient to promotion string converter
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> |