Home  >  Article  >  Backend Development  >  想用php将数据库里的内容存为如下数组,求怎么写?

想用php将数据库里的内容存为如下数组,求怎么写?

WBOY
WBOYOriginal
2016-06-23 13:35:28853browse

$result = mysql_query("SELECT area_name,area_parent_id,area_id FROM shopnc_area where area_id>5 and area_deep $area_array=array();
while($row = mysql_fetch_array($result))
  {
不知道怎么写了。

想要的数据库格式:
$area_array =  array ( 
                        2 => array ( 'area_name' => '天津', 'area_parent_id' => '0', ), 
                       40 => array ( 'area_name' => '天津', 'area_parent_id' => '2', ), 
                        );
其中:2,40的值为area_id的值。谢谢。


回复讨论(解决方案)

while($row = mysql_fetch_array($result)){	$area_array[$row['area_id']]['area_name'] = $row['area_name'];	$area_array[$row['area_id']]['area_parent_id'] = $row['area_parent_id'];}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn