I'm attempting to count the number of rows in my database for a pagination script. My entire script works until it comes down to counting the rows.
This is the code that should be counting my rows[$conn is a variable set with my database login - it is used throughout this code and works, except for this bit].
$limit = 2;
$rows = mysql_num_rows(mysqli_query($conn, "SELECT count(*) FROM pilotOperators"));
$total=ceil($rows/$limit);
To test my code I added this to the end of my page:
echo "Total:" . $total . "<br>";
echo "Rows:" . $rows . "<br>";
echo "Limit:" . $limit . "<br>";
And this is the result taken from my source code:
Total:0<br>Rows:<br>Limit:2<br>
I've tried several variations and such, but nothing is returning a number.
SOLVED: Thanks to two different answers(apparently I had two mistakes).
One of my lines was changed to:
$rows = mysqli_num_rows(mysqli_query($conn, "SELECT * FROM pilotOperators"));
And it works like a charm now.
Thanks Mureinik, and EyasSH
mysql_*()with calls tomysqli_*(). The two APIs are different and can't be intermixed. You also shouldn't usemysql_*()for new code. It's deprecated and will be removed from PHP 7 later this year.