I have a table in a MySQL database with shops and days. I need to check if the shop is open on that day.
Before checking if a shop is open following this method: Find next time business is open; mysql hours calculation I need to check whether the shop is on some holiday before checking if it's open or not.
Is it good to have a table with :
Shop ID | Days
xxx | number,number,number, etc..
that the application (written in PHP) queries checking whether the [yday] is contained in the Days string (a comma separated values string)? The Shop ID will be a foreign key in the Shops table, and the application will always know in advance which shops to run this query for, not the other way around.
I have found no computationally cheap or elegant solution around so far. It may be a very simple question, but the solutions are soo many I'm having a hard time figuring out the different performance issues.
Edit 1
Considering also the performance implications of the query as follows, having considered @GordonLinoff answer as the best solution:
$ShopId = //a POST or GET $day = //a POST or GET $query = mysqli_query($con,"SELECT day FROM table WHERE ShopId = '$ShopId' AND day = $day"); if(mysql_num_rows($query)== 0){ echo "Shop open"; } else{ echo "Shop closed"; } mysqli_close($con);