来自数据库PHP的数组

时间:2013-02-27 13:20:14

标签: php database arrays multidimensional-array

您好,我需要从数据库创建一个数组; myTable看起来像这样

id           | name       | address |
-------------+------------+---------------
1            | Peter      | Union Streeet|
2            | John       | King Street  | 

然后我有sql将从数据库中选择值

$record=mysql_query("SELECT * FROM myTable");
while($row=mysql_fetch_assoc($record)){
      //fill array how to fill array that will look like bellow from database???
}

我需要创建看起来像这样的数组

$list = array (
    array('$row[id]', '$row[name]', '$row[address]'),
    // array('$row[id]', '$row[name]', '$row[address]')
    // FOR EACH LINE FROM DATABASE NEW NESTED ARRAY
);

2 个答案:

答案 0 :(得分:3)

$record=mysql_query("SELECT * FROM myTable");
$list = array();
while($row=mysql_fetch_assoc($record)){
      //fill array how to fill array that will look like bellow from database???
    $list[] = row;
}

答案 1 :(得分:2)

试试这个:

while($row=mysql_fetch_assoc($record)){
     $list[] = $row;
}

echo "<pre>";
print_r($list);