I'm trying to build a in/out marker in PHP, but having problems when trying to choose a date limit. I have a very long SQL but have simplified it to this:
if (($office_name == "All") && ($group_name == "All")
&& ($fullname == "All") && ($from_date == '') && ($to_date == ''))
{
$query2 = "select * from ".$db_prefix."info";
$result2 = mysql_query($query2);
}
elseif (($office_name == "All") && ($group_name == "All")
&& ($fullname == "All") && ($from_date != '') && ($to_date != ''))
{
$query2 = "select employees.empfullname, info.fullname, info.`inout`,
info.timestamp
from employees, info
where info.timestamp >= '".$from_date."'
and info.timestamp <= '".$to_date."'
and employees.empfullname = info.fullname
and employees.tstamp IS NOT NULL";
$result2 = mysql_query($query2);
}
if($result2 === FALSE) {
die(mysql_error());
}
while($row = mysql_fetch_array($result2)){
//some more code
}
Basically if the 'from' and 'to' fields are filled then it searches in timestamp and returns values that are greater or equal to 'from' and less or equal to 'to'. I think the problem is there because when I don't put anything (first case) it shows just fine.
No matter what I put inside the while loop nothing is return. There are no errors reported and connection to DB is well. I have no idea what could be wrong with this, or how to fix it since i don't know what is wrong and no errors show.