5 and area_"/> 5 and area_">

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

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

WBOY
WBOYOriginal
2016-06-13 12:19:16869browse

想用php将数据库里的内容存为如下数组,求怎么写?
$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的值。谢谢。
------解决思路----------------------

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

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