How to create a loop for my IF statement
if the following day has reached its limit and it should stop once the date is available?
The scenario...
I am working on a Logistics application where a specific courier can only handle limited transactions per day. The application should give the customer the best possible date of delivery as per the product he ordered.
eg.
Product A = 13 Days to be delivered
Product B = 14 Days to be delivered
So, if the customer selected Product A, the best delivery date will be today's date + 13 days.
Let say the Best Delivery Date is 27/11/2019.
But since the courier has a per-day limit of deliveries, I should count first in the Database if the limit has reached or not. If the limit has reached on that day then I will show to the customer the next available date which is 28/11/2019.
My Code
$courierLimitPerDay = 25;
$date = date('Y-m-d', strtotime($today. ' + '.$productsDeliveyDay.' days'));
$sql = "SELECT COUNT(*) FROM `product_delivery` WHERE delivery_date = '$date' AND courier_id = '$courierId'";
$query = $connect->query($sql);
$result = $query->fetch_row();
if($result[0] == $courierLimitPerDay) {
$date = date('Y-m-d', strtotime($date . ' + 1 days'));
$sql = "SELECT COUNT(*) FROM `product_delivery`
WHERE delivery_date = '$date' AND courier_id = '$courierId'";
$query = $connect->query($sql);
$result = $query->fetch_row();
}
echo "Best Delivery Date is on ". $date;