1

I have a table called that's value is the $instructor:

ID start_date_time end_date_time
1 2018-04-01 10:00:00 2018-04-02 14:00:00

The user in imputing a desired start and end date&time through a from to create a new event. I am seeking to check for any conflicting events via a mysqli_num_rows with a SELECT query as such :

$sql = "SELECT * FROM `$instructor` WHERE ('$FromDateTime' between start_date_time and end_date_time) OR ('$ToDateTime' between start_date_time and end_date_time) LIMIT 1";
    $query = mysqli_query($db_conx4, $sql);
    $instructorcheck = mysqli_num_rows($query);

I would then later on call the number of rows during an if() statement :

if ($instructorcheck > 0 || !$instructorcheck){.... 

I'm not sure if my formatting is incorrect but I keep on receiving a : mysqli_num_rows() expects parameter 1 to be mysqli_result error.

I'm not sure my statement is correct because what if a user requests and event with the start and end date&time being outside the existing events such as here : from 2018-04-01 09:00:00 to 2018-04-02 15:00:00... Then neither the start or end times will fall between the start_date_time and end_date_time in the table and the number of rows returned would be zero I presume... ?

Dharman
  • 30,962
  • 25
  • 85
  • 135
danny26b
  • 463
  • 2
  • 13
  • Then `mysqli_query($db_conx4, $sql)` doesn't return a value of type `mysqli_result`. Did you check for errors (`mysqli_error_list()`)? – Caramiriel Mar 08 '18 at 18:36
  • I have this in place : `if (!$sql) {print_r(mysqli_error_list($sql));}` yet I'm not getting any listing other than the parse error from above.. maybe my query for the listing of errors is invalid ? – danny26b Mar 08 '18 at 18:50
  • Does this answer your question? [mysqli\_fetch\_assoc() expects parameter / Call to a member function bind\_param() errors. How to get the actual mysql error and fix it?](https://stackoverflow.com/questions/22662488/mysqli-fetch-assoc-expects-parameter-call-to-a-member-function-bind-param) – Dharman Dec 07 '20 at 23:02

1 Answers1

1

I would remove the !$instructorchecklocated in your if statement. It shouldn't be used this way - your code should run now.

JAMES RYAN
  • 97
  • 6