章节表
CHID | Name | Active | Order
1 Ch2 Y 2
2 Ch5 N 10
3 Ch1 Y 1
页表
PID | Name | Active | CHID | Order
1 Ch1P1 Y 1 1
2 Ch1P2 Y 1 2
3 Ch2P2 Y 3 2
4 Ch2P1 Y 3 1
5 Ch5P1 N 2 1
当前结果列出了每一章,但也列出了每一章下的每一页。我将当前脚本的“foreach”部分与一些 Dreamweaver 构建的 PHP 合并。
我在找:
Ch1
Ch1P1
Ch1P2
Ch2
Ch2P1
Ch2P2
我当前的 php/mysql 脚本。
$myarray = array();
mysql_select_db($database, $connection);
$query_GetModuleChaptersPages = sprintf("SELECT chapters.CHID, chapters.Chapter_Name AS ChapterName, chapters.MID, chapters.`Order` AS ChapterOrder, pages.PID, pages.Page_Name AS PageName, pages.CHID, pages.Is_Active, pages.`Order` AS PageOrder FROM chapters, pages WHERE chapters.MID = 1"));
$GetModuleChaptersPages = mysql_query($query_GetModuleChaptersPages, $connection) or die(mysql_error());
$row_GetModuleChaptersPages = mysql_fetch_assoc($GetModuleChaptersPages);
$totalRows_GetModuleChaptersPages = mysql_num_rows($GetModuleChaptersPages);
while ($row = mysql_fetch_array($GetModuleChaptersPages, MYSQL_ASSOC)) { $myarray[$row['ChapterName'] ][] = $row['PageName']; }
print "<ul>";
foreach ($myarray as $key => $val) {
print "<li><h5>";
print $key;
print "</h5><ul>";
for($i=0;$i<count($val);$i++){
print "<li>";
print $val[$i];
print "</li>";
}
print "</ul></li>";
}
print "</ul>";