Reputation: 15484
I have a mysqli_result Object doing this:
$mysqli->real_query("SELECT * FROM users WHERE `level` > 2");
$user_list = $mysqli->use_result();
print_r($user_list); die();
Doing so, the print_r give me:
mysqli_result Object ( [current_field] => 0 [field_count] => 6 [lengths] => [num_rows] => 0 [type] => 1 )
Later im just using while ($row = $user_list->fetch_assoc())
to parse all the content. The think is before doing the while I want to retrieve the num_rows
from the mysqli_result Object but doing just $user_list['num_rows'] does not work:
Fatal error: Cannot use object of type mysqli_result as array
Upvotes: 1
Views: 10162
Reputation: 459
Try this, in my case it works :)
$query = "SELECT * FROM users WHERE `level` > 2";
$result = mysqli_query($connection, $query);
while ($rows = mysqli_fetch_array($result, MYSQLI_NUM)) {
var_dump($rows);
}
Upvotes: 1
Reputation: 16297
$mysqli->real_query("SELECT * FROM users WHERE `level` > 2");
$user_list = $mysqli->use_result();
echo $user_list->num_rows;
Upvotes: 0
Reputation: 6852
You have to get the num_rows
using the $result->num_rows
if ($result = $mysqli->query("")) {
/* determine number of rows result set */
$row_cnt = $result->num_rows;
}
After getting num_rows
you can fetch it.
Upvotes: 1