I recognize this has been asked multiple times here and I've tried all exhaustible possible solutions. Might there be something inherently incorrect with my query as to why it would return false no matter if my query returns data?
$q_log_dates = "SELECT * FROM log_dates WHERE week_date ='" . $currentWeek . "'";
$q_log_dates_result = mysqli_query($connection, $q_log_dates);
$numResults = mysqli_num_rows($q_log_dates_result);
if ($numResults > 0) {
echo "data";
} else {
echo "no data";
}
Just use object-oriented MySQLi functions. In your case $q_log_dates_result
is an object and you can use its properties.
$q_log_dates_result = mysqli_query($connection, $q_log_dates); //-Procedural
//OR $q_log_dates_result = $connection->query($q_log_dates); //Object oriented
if ($q_log_dates_result->num_rows > 0) {
echo "data";
} else {
echo "no data";
}
mysqli_query returns type of object, where mysql_num_rows expects parameter 1 to be resource. You cannot mix mysqli_* functions with mysql_* ones, they are not interchangeable.
I's highly recommended to drop using mysql_* ones and stick to the other libraries such as already mentioned MySQLi
You are using
mysqli_query
, so for $numResults , you should use
mysqli_num_rows