[Solved] while loop inside an array


You need to iterate through the results and add the values to your data array:

$query = mysql_query("SELECT * FROM tableName WHERE status="confirm" ORDER BY datetime DESC ");
$data = array();
while ($invoice = mysql_fetch_assoc($query)) {
  $data[] = array(
    'firstname' => $invoice['firstname'],
    'lastname' => $invoice['lastname'],
    'age' => $invoice['age'],
  );
}

mysql_fetch_assoc($query) returns only one row, so as long as it returns a result row (while), the loop is running and adds the values to the $data array.

5

solved while loop inside an array