php将json传递给angularjs

this is my php code,

    $count=mysql_num_rows($query);

if ($count > 0) {
  // output data of each row
  $foodList[] = array();
  while($row =mysqli_fetch_assoc($result))
  {
      $foodList[] = $row;
  }
} else {}

echo json_encode($foodList);

this is my js code:

var $promise = $http.post('foodList.php');

$promise.then(function(msg){
  var foodList = msg.data;

  if (foodList) 
    {
      //$scope.foodList = foodList;
      alert(foodList);
    }
  else
    {
      //$scope.msg = "Error user name or password";
    }

this is output:

$promise.then(function(msg){*msg = Object {data: Array[1], status: 200, config: Object, statusText: "OK"}* var foodList = msg.data;*foodList = [Array[0]]*

So: actually 3 data in my data base, but in output just only Array[1]? How to fix it ? THX

Your php syntax and the usage of commands are wrong in some places. Here is the corrected code. Please compare and see the difference.

$count=mysql_num_rows($result);

if ($count > 0) {

  // output data of each row
  $foodList = array();

  while($row =mysqli_fetch_assoc($result))
  {        
      array_push($foodList, $row);
  }
}

echo json_encode($foodList);

This should work if you are selecting the rows correctly.

Your count the $query variable so in your while loop use $query variable

<?php
$count=mysql_num_rows($query);

if ($count > 0) {
  // output data of each row
  $foodList = array();
  while($row =mysqli_fetch_assoc($query))
  {
      $foodList[] = $row;
  }
}

echo json_encode($foodList);

?>