Skip to content Skip to sidebar Skip to footer

Looping Through Query Results Multiple Times With Mysqli_fetch_array?

Does the mysqli_fetch_array() function remove each value as it returns it? If not, how can I go back to the top of the array when I've finished looping through it? I need to loop t

Solution 1:

You could use the mysqli_fetch_all function to return all results as an array, which you could then manipulate as you would any other array in PHP:

$arr = mysqli_fetch_all($namesList);

Solution 2:

a magic

$data = array();
while ($row = mysqli_fetch_array($res))
{
    $data[] = $row;
}

foreach ($dataas$row) echo$row['name'];
foreach ($dataas$row) echo$row['name'];
foreach ($dataas$row) echo$row['name'];
foreach ($dataas$row) echo$row['name'];
foreach ($dataas$row) echo$row['name'];
foreach ($dataas$row) echo$row['name'];

Post a Comment for "Looping Through Query Results Multiple Times With Mysqli_fetch_array?"