我想用我的mysql表获得相同的结果。在我的桌子下面:
CREATE TABLE IF NOT EXISTS `map_point` (
`Id` int(11) NOT NULL AUTO_INCREMENT,
`Location` varchar(80) NOT NULL,
`type` varchar(80) NOT NULL,
`icon` varchar(70) NOT NULL DEFAULT '',
PRIMARY KEY (`Id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=898 ;
类型是Phase1,Phase2 ......最终的多维数组必须显示如下:
$data = array ( "Phase1" => array("name"=>"Phase 1", "icon"=>"icons/iconb.png"),
"Phase2" => array("name"=>"Phase 2", "icon"=>"icons/icong.png"),
"Phase3" => array("name"=>"Phase 3", "icon"=>"icons/iconr.png"),
"Phase2p" => array("name"=>"Phase 2+", "icon"=>"icons/icony.png"),
"Phase3p" => array("name"=>"Phase 3+", "icon"=>"icons/iconpi.png"),
"RollOut2012" => array("name"=>"Roll Out 2012","icon"=>"icons/iconor.png"),
"RollOut120sites" => array("name"=>"Roll Out 120 Sites", "icon"=>"icons/iconma.png"),
);
提前感谢您的帮助。
答案 0 :(得分:1)
你可以试试那种
$jsondata = array();
$result = mysql_query("SELECT type AS name, icon FROM map_point");
while($row = mysql_fetch_assoc($result)) {
if(!array_key_exists($row['type'], $jsondata))
$jsondata[$row['name']] = $row
else
array_push($jsondata[$row['name']] , $row)
}