Sie sollten die beiden Abfragen verbinden:
SELECT
Rest_Details.Resturant_ID,
Rest_Details.Resturant_name,
Delivery_Pcode.Pcode,
Opening_hrs.Open_time,
Opening_hrs.Closing_time
FROM Rest_Details
JOIN Deliver_Pcode ON Delivery_Pcode.Restaurant_ID=Rest_Details.Restaurant_ID
LEFT JOIN Opening_hrs ON Opening_Hrs.Restaurant_ID=Rest_Details.Restaurang_ID
AND Day_of_week = WEEKDAY(NOW()) AND CURTIME() BETWEEN Open_time AND Closing_time
WHERE Delivery_Pcode.Pcode LIKE '%$pcode%'
Weil es ein LEFT JOIN
ist , Open_time
und Closing_time
werden ausgefüllt, wenn das Restaurant geöffnet ist, andernfalls sind sie NULL
. Das PHP, das die Ergebnisse anzeigt, kann dies also überprüfen:
while ($row_prods = mysqli_fetch_array($sql)) {
$rest_id = $row_prods['Resturant_ID'];
$rest_name = $row_prods['Resturant_name'];
$output .= '<div id="products">' .
' <p id="rest_name">' . $rest_name . '</p>';
if ($row_prods['Open_time']) {
$output .= '<p> open ' . $row_prods['Open_time'] . ' close ' . $row_prods['Close_time'];
}
$output .= "</div>";
$i++;
}