I have difficulties getting rows from a table in a database because mysqli_num_rows
always returns false. This is an extract of my code:
$query = "SELECT * FROM table1 WHERE user = '$user'";
if (mysqli_num_rows(mysqli_query($conn, $query)))
{
$row = mysqli_fetch_row($results);
echo $row[1]
}
I did not get the result of the echo $row[1]
. I then substituted the if
statement with another:
if (!mysqli_num_rows(mysqli_query($conn, $query)))
echo 'no rows!'
and got 'no rows!' on the browser.
I have successfully connected to the database and other queries work just fine. Please, I would like to understand why mysqli_num_rows
will return false even though I have rows in the table which match the query.