php - How to use array inside while loop so it can track every id fetching from database? -
i'm fetching multiple rows database. that's why use while
loop need every individual id inside while
loop. how can use array inside while loop? friendid
prints last result loop.i don't want print result inside loop.
while ($row = mysqli_fetch_assoc($run_sql)) { $name = $row['name']; $friendid = $row['id']; } echo $friendid;
create empty array before while
loop. in each iteration of loop, append fetched row this array.
$resultarr = array(); while ($row = mysqli_fetch_assoc($run_sql)){ $resultarr[] = array($row['id'], $row['name']); } // display $resultarr array var_dump($resultarr);
Comments
Post a Comment