1

嗨,我需要从数据库创建一个数组;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
);
4

2 回答 2

4
$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;
}
于 2013-02-27T13:22:48.310 回答
2

试试这个 :

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

echo "<pre>";
print_r($list);
于 2013-02-27T13:23:32.523 回答