Array from Database PHP

痴心易碎 提交于 2021-01-29 03:08:30

问题


Hi I need to create an array from database; myTable looks like this

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

Then I have sql that will select values from database

$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???
}

I need to create array that will look like this

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

回答1:


$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;
}



回答2:


Try this :

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

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


来源:https://stackoverflow.com/questions/15113144/array-from-database-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!