0

I have this Query as below:

$timeChk = "SELECT COUNT(id) as inTime, connections.* FROM connections WHERE (busID = '".$mid."' AND cusID = '".$tid."') OR (busID = '".$tid."' AND cusID = '".$mid."') AND FROM_UNIXTIME(timeIn,'%Y-%m-%d') = CURDATE() AND timeOut = '0'";

its always printing a row result.

Im suspecting that the COUNT(id) is causing the issue. This query should not return any results and

$timeChk['inTime'] should be zero (0) as per the database below:

in my database at this specific moment i do not have a table "timeOut" which is equalt to "0" || ''(blank)

What is the matter with this query?

How can i pull a $timeChk['inTime'] = 0

HERE IS DATABASE STRUCTURE:

id     busID    cusID     timeIn        timeOut
25      23       24     1593702664    1593703635

the goal of this table is to log someone in if the query above the $timeChk['inTime'] = 0; and if it returns $timeChk['inTime'] = 1; it will log the person out.

please help

  • 1
    You probably need brackets round `(busID = '".$mid."' AND cusID = '".$tid."') OR (busID = '".$tid."' AND cusID = '".$mid."')`. – Nigel Ren Jul 02 '20 at 15:43
  • Assuming SQL mode `ONLY_FULL_GROUP_BY` is disabled, `SELECT COUNT` will always return a result row, regardless of the `WHERE` condition or any other fields selected in the query. If no rows match the condition, it will return 0 for the `COUNT` and `null` for the field values. If `ONLY_FULL_GROUP_BY` is enabled, your query will return an error. – Nick Jul 02 '20 at 15:54

0 Answers0