问题
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