Var_dump shows only one row, couple hundreds are supposed to be returned

Query is correct, it’s simple SELECT * FROM example and it returns all rows in phpMyAdmin.
Let’s start with this:

echo "<pre>";
var_dump($dbResult);
echo "</pre>";

Results in:

object(mysqli_result)#2 (5) {
  ["current_field"]=>
  int(0)
  ["field_count"]=>
  int(5)
  ["lengths"]=>
  NULL
  ["num_rows"]=>
  int(110)
  ["type"]=>
  int(0)
}

Note: ["num_rows"]=>int(110).

Now:

echo "<pre>";
$dbResult = $dbResult->fetch_assoc();
var_dump($dbResult);
echo "</pre>";

When I fetch_assoc() it. I get only first row. Which is kind of correct, but there are 110 of them. And it returns only first row.

And what exactly is your question?

Well. How to fetch all results, instead of just first row?

foreach ($dbResult as $row) {
    print_r($row);
}

Shouldn’t var_dump() dump all the arrays?
Also, your resolution also returns single result.

no.

which PHP version are you using?

1 Like

I think that is due to you overwriting $dbResult

If you change that to $row = $dbResult ->fetch_assoc(); do you get better results? That or you have something else going on here that we can’t see with your code example.

1 Like

No that pretty much it. I include database connection, drop the query and problem is already here.

PHP 7.

I don’t know what’s happening with this world. I got it, and still wondering why always-working solution stopped working… eh… I’m gettin’ old.

Thanks for help.

well, I prefer PDO - much easier to use when it comes to prepared statements.

Okay, so fetch_assoc is not what you want. That fetches a single row. You want to use fetch_all to get all rows at once. Otherwise, you have to use a loop to get all of the rows, one at a time using fetch_assoc

http://us2.php.net/manual/en/mysqli-result.fetch-all.php
http://us2.php.net/manual/en/mysqli-result.fetch-assoc.php

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.