I have a function. in that function in have a select query. another query should return the number of results that will be in the first query. I have this code:
function name ($f){
global $db;
...
$results = "SELECT `a` FROM `b` WHERE $where";
$results_num = ($query = mysqli_query($db, $results)) ? mysqli_num_rows($results) : 0;
echo $results;
echo $results_num;
}
will echo:
SELECT `a` FROM `b` WHERE `keywords` LIKE '%abc%'0
what is just $results but not $results_num? I do not understand why echo $results_num wont be shown and why there is a 0 at the end of $results so if there is someone who could give me advise to solve this I really would appreciate. thanks a lot.
Firstly,
$results_numis zero and is being output (that’s why there’s a0at the end of your output). That’s because this code is wrong:Breaking it out a little:
And the second line should actually be:
You need to pass the query handle to
mysqli_num_rows(), not the SQL.