amanuel2
amanuel2

Reputation: 4646

How to fetch all items in array?

Im confused on how to fetch all of the stuff in my array... Its like a table from a SQL.. I can get one of them doing the following:

if ($result = mysqli_query($connection, "SELECT * FROM `todoTable` WHERE 1")) {
printf("Select returned %d rows.\n", mysqli_num_rows($result));
$row = mysqli_fetch_array($result);
echo $row[0];
mysqli_free_result($result);
}

But when i try to do all of it... It fails..

if ($result = mysqli_query($connection, "SELECT * FROM `todotable` WHERE 1")) {
     printf("Select returned %d rows.\n", mysqli_num_rows($result));
     // Fetch all
    $row = mysqli_fetch_all($result,MYSQLI_ASSOC);
    echo $row;

    mysqli_free_result($result);
  }

Please Help.. Thankyou

Upvotes: 2

Views: 94

Answers (1)

Mr.Z
Mr.Z

Reputation: 77

Try using foreach to iterate through the array, I usually get what I want using that method.

$row = mysqli_fetch_all($result,MYSQLI_ASSOC);
foreach($row as $value)
     echo $value;

Upvotes: 3

Related Questions