3 Votes Vote

Performance mySql PHP - Closing days of the week

Posted by topdog 26 days ago Questions| closed mysql finaldate All

What would be the fastest way to run this to check for days of the week that a business is closed?

$closingDaysCheck = mysql_query("SELECT * FROM businessClosingDays WHERE Bid='$Bid' LIMIT 1", $con);
        if($closingDaysCheck) {
                    if(mysql_num_rows($closingDaysCheck) >0) {
                        while ($closed = mysql_fetch_assoc($closingDaysCheck)) {
                 if((date("w", $finalDate) == 0) && ($closed[0] != 0)) { // SUNDAY
            $active = 'inactive';}
            else if((date("w", $finalDate) == 6) && ($closed[6] != 0)) { // SATURDAY
            $active = 'inactive';}
            else if((date("w", $finalDate) == 5) && ($closed[5] != 0)) { // FRIDAY
            $active = 'inactive';}
            else if((date("w", $finalDate) == 4) && ($closed[4] != 0)) { // THRUSDAY
            $active = 'inactive';}
            else if((date("w", $finalDate) == 3) && ($closed[3] != 0)) { // WEDNESDAY
            $active = 'inactive';}
            else if((date("w", $finalDate) == 2) && ($closed[2] != 0)) { // TUESDAY
            $active = 'inactive';}
            else if((date("w", $finalDate) == 1) && ($closed[1] != 0)) { // MONDAY
            $active = 'inactive';}
            else {$active = 'active';}
                        }
                    }
                } 

Here is the database, the last day is Sunday and it's closed:

CREATE TABLE `businessClosingDays` (
  `Bid` varchar(40) NOT NULL,
  `1` tinyint(1) NOT NULL,
  `2` tinyint(1) NOT NULL,
  `3` tinyint(1) NOT NULL,
  `4` tinyint(1) NOT NULL,
  `5` tinyint(1) NOT NULL,
  `6` tinyint(1) NOT NULL,
  `0` tinyint(1) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

INSERT INTO `businessClosingDays` VALUES('9', 0, 0, 0, 0, 0, 0, 1);

Originally asked by: Sebastian on Stack Overflow

Discuss Bury


Who Voted for this Question