我想创建一个带有如下菜单的页面:

main1
 >sub1.1
   >sub1.1.1
   >sub1.1.2
 >sub1.2
   >sub1.2.1
main2
 >sub2.1
   >sub2.1.1
   >sub2.1.2
 >sub2.2
   >sub2.2.1


但是当前正在发生的是:

main1
 >sub1.1
 >sub1.2
   >sub1.1.1
   >sub1.1.2
   >sub1.2.1
main2
 >sub2.1
 >sub2.2
   >sub2.1.1
   >sub2.1.2
   >sub2.2.1


这是我的代码:

<?php

$categories = array();

// main-categories
$sql = 'SELECT * FROM forum_market_main ORDER BY market_main_id ASC';
$result = mysql_query($sql);

while ($row = mysql_fetch_array($result)) {
    $categories[$row['market_main_id']] = $row;
}

// sub-categories
$sql = 'SELECT * FROM forum_market_sub ORDER BY market_sub_id ASC';
$result = mysql_query($sql);

while ($row = mysql_fetch_array($result)) {
    $categories[$row['market_main_id']]['forum_market_sub'][] = $row;
}

// sub2-categories
$sql = 'SELECT * FROM forum_market_sub2 ORDER BY market_sub2_id ASC';
$result = mysql_query($sql);

while ($row = mysql_fetch_array($result)) {
    $categories[$row['market_main_id']]['forum_market_sub']['forum_market_sub2'][] = $row;
}

print_r($categories);

?>


您可以在此处亲自查看:click-查看源代码模式,以便于理解。

为了使整个菜单系统都能很好地显示,我的奖金问题是PHP代码或其他什么。

非常感谢您的帮助!

最佳答案

我建议看一下click,了解如何为分层数据设计数据库。

10-07 21:28