PHP Mysql选择数组格式

时间:2014-04-08 12:18:22

标签: php mysql

我正在从这样的Mysql数据库中读取数据:

$result = mysqli_query($con,"SELECT * FROM myTable");

while($row = mysqli_fetch_array($result))
  {

  echo $row['field1'] . " " . $row['field2'];

  }

而不是输出这样的记录:

 echo $row['field1'] . " " . $row['field2'];

我需要将它们变成以下格式:

$list = array(

        array('field1'=>'something here', 'field2'=>'something else')

  );

我该怎么做?

1 个答案:

答案 0 :(得分:2)

$result = mysqli_query($con,"SELECT * FROM myTable");

while($row = mysqli_fetch_array($result)){

  $list[] = $row;

}