0

我想获得与我的 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"),                   
);

预先感谢您的帮助。

4

1 回答 1

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)
}
于 2013-02-25T16:12:35.590 回答