PHP Mysql Sub Menu array

Можете ли вы помочь в создании
Выпадающее меню (подменю) с Mycode Cat.php
ФАЙЛ Включить в заголовок
Меню

/////// ( Home )//////////
include_once("./includes/config.php") ;

$mysqlQuery=new mysqlQueryClass();

$query="SELECT `catagory_id`, `name` FROM `catagories` WHERE `level` = 1";
$mysqlQuery->mysqlQueryWOF($query);

while (list($catagory_id,$name) = mysql_fetch_array($mysqlQuery->result))
{
$cats .= "<b>::</b> <a href='cat-$catagory_id,start-0'>$name</a><br>";
}///(SubMenu level 2 About From Home)//////
$mysqlQuery=new mysqlQueryClass();

$query="SELECT `catagory_id`, `name` FROM `catagories` WHERE `level` = 2";
$mysqlQuery->mysqlQueryWOF($query);

while (list($catagory_id,$name) = mysql_fetch_array($mysqlQuery->result))
{
$cats .= "<b>::</b> <a href='cat-$catagory_id,start-0'>$name</a><br>";
}

Фотографий:http://s12.postimg.org/v2yxhk8gt/2016_01_17_06_21_08.png Уровень 1 = Меню Уровень2 = Подменю

0

Решение

$mysqlQuery=new mysqlQueryClass();

$query="SELECT a.`catagory_id` parent_cat_id, a.`name` parent_cat, b.category_id, b.name
FROM `catagories` a
LEFT JOIN `catagories` b on b.level = 2 and a.category_id = b.category
WHERE a.`level` = 1";

$mysqlQuery->mysqlQueryWOF($query);
$id2name = array();
$cat_tree = array();

while (list($parent_id,$parent,$cat_id,$cat) = mysql_fetch_array($mysqlQuery->result)) {
$id2name[$parent_id] = $parent;
$id2name[$cat_id] = $cat;
$cat_tree[$parent_id][] = $cat_id;
}

foreach ($cat_tree as $parent_id => $child_ids) {
$name = $id2name[$parent_id];
$cats .= "<b>::</b> <a href='cat-$parent_id,start-0'>$name</a><br>";

foreach ($child_ids as $id) {
if (is_null($id)) continue;
$child = $id2name[$id];
$cats .= "<b>::::</b> <a href='cat-$id,start-0'>$child</a><br>";
}
}
0

Другие решения

Вы можете создать меню и подменю следующим образом:

$mysqlQuery=new mysqlQueryClass();
$query="SELECT `catagory_id`, `name` FROM `catagories` WHERE `level` = 1";
$mysqlQuery->mysqlQueryWOF($query);while (list($catagory_id,$name) = mysql_fetch_array($mysqlQuery->result))
{
$cats .= "<b>::</b> <a href='cat-$catagory_id,start-0'>$name</a><br>";

$query="SELECT `catagory_id`, `name` FROM `catagories` WHERE `level` = 2 AND main_category = ". $catagory_id ;
$mysqlQuery->mysqlQueryWOF($query);
while (list($scatagory_id,$sname) = mysql_fetch_array($mysqlQuery->result))
{
$cats .= "<b>::</b> <a href='cat-$scatagory_id,start-0'>$sname</a><br>";

}
}
0

По вопросам рекламы [email protected]