I have a mysql query in php that is set to run hourly by a cron job. Sometimes the results are correct and sometimes I get back a result thats on a different date than being queried. As mysql is being run in a different timezone i am using php date() time()
to correct the current hour and date. I first use count in mysql to every see if any records exist matching the criteria. And if they do i run the same query and grab the data. I am looking for records that are for the current day. Have a time frame of an hour or hour and a half ahead of the current time and match a couple other parameters being the JobStatus and TechID columns. Sometimes it runs correctly and sometimes I get records showing that are for days ahead. The column for the time in the database is a varchar as I just simply needed the current time to match a string as the appointment is entered into the database as 1PM
or 9:30AM
or whatever time slot was selected on the form in hour or half hour time frames. I have as well added my database structure below too. I have checked the database to see if its corrupt and it checks out fine.
Am I maybe going about this query incorrectly?
date_default_timezone_set("America/Chicago");
$SearchDate = date('Y-m-d', time());
//CURRENT TIME PLUS ONE HOUR
$TimePlusHour = date('gA', strtotime("+1 hours"));
//CURRENT TIME PLUS ONE HOUR PLUS SETTING MINUTES TO HALF HOUR
$Plus30 = date('g:30A', strtotime("+1 hours"));
$sqlCount = "SELECT COUNT(*) AS 'count' FROM ServiceTickets WHERE Date=
'".$SearchDate."' AND Time='".$Plus30."' OR Time='".$TimePlusHour."'
AND JobStatus='1' OR JobStatus='3' AND TechID= '".$TechID."' ";
$sql1 = "SELECT * FROM ServiceTickets WHERE Date= '".$SearchDate."' AND
Time='".$Plus30."' OR Time='".$TimePlusHour."' AND JobStatus='1' OR
JobStatus='3' AND TechID= '".$TechID."' ORDER BY id ASC";
Database structure
CREATE TABLE `ServiceTickets` (
`id` bigint(11) unsigned NOT NULL AUTO_INCREMENT,
`FirstName` varchar(255) DEFAULT NULL,
`LastName` varchar(255) DEFAULT NULL,
`Phone` varchar(20) DEFAULT NULL,
`Address` varchar(255) DEFAULT NULL,
`Address2` varchar(255) DEFAULT NULL,
`City` varchar(100) DEFAULT NULL,
`State` varchar(50) DEFAULT NULL,
`Zip` varchar(10) DEFAULT NULL,
`Email` varchar(255) DEFAULT NULL,
`Date` date DEFAULT NULL,
`Time` varchar(50) DEFAULT NULL,
`JobDesc` text,
`JobStatus` varchar(10) DEFAULT NULL,
`TechID` varchar(3) DEFAULT NULL,
`LastModified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
)
ENGINE=MyISAM AUTO_INCREMENT=21 DEFAULT CHARSET=latin1;