我正在尝试为菜单创建一个多维数组,其中seccond数组表示de子菜单(子类别)。问题是它工作正常,但加载速度非常慢,我希望能找到一个更好,更清洁的解决方案来加快速度。
我正在使用的功能是下一个功能:
public function getMenu() {
$result = $this->db->FetchArrayAll("SELECT ml . * , m.icon, m.body_position FROM menu AS m inner JOIN menu_language AS ml ON m.id = ml.id_menu AND ml.id_language ='".$this->id_lenguage."' WHERE m.body_position = '".$this->body_position."' ORDER BY m.position");
$retorno = array();
foreach ($result as $r) {
$submenu = $this->db->FetchArrayAll("SELECT sl . * , s.icon, s.name, s.position FROM submenu AS s inner join submenu_language AS sl ON s.id = sl.id_submenu AND sl.id_language ='".$this->id_lenguage."' WHERE s.id_menu ='".$r['id_menu']."' ORDER BY s.position");
$retorno[] = array(
"id" => $r['id_menu'],
"icon" =>$r['icon'],
"name" => $r['menu'],
"body" => $r['body_position'],
"submenu" => $submenu
);
}
return $retorno;
}
$this->db
代表我的数据库类,其中FetchArrayAll是一个看起来像这样的简单函数:
public function FetchArrayAll($query) {
$q_query = mysql_query($query);
$r = array();
while($q = mysql_fetch_array($q_query)) {
array_push($r, $q);
}
return $r;
}
只是写了它可能包含一些错误,但最终的功能正常工作,无论如何我也会感谢任何评论来优化所写的任何函数。