1

我正在使用从 SQL 数据库中提取的内容修改一个用 PHP 构建的站点。原始开发人员使用以下代码创建了导航。它从 CMS 页面创建导航 - 它适用于顶级页面,但我正在尝试修改子页面的呈现方式。

我想要它做的是当存在子页面时,它首先打开一个包含格式的 DIV,然后使用下面的“while”语句填充子页面菜单。最后,当 subpagemenu 完成时,它会关闭 DIV。

在完成填写子页面菜单的循环之前,我似乎无法确定哪个条件“打开”了子页面菜单。

任何和所有的帮助表示赞赏 - 谢谢!

<?
$pagesrc = $_SERVER['SCRIPT_NAME'];
$getPID_sql = "SELECT * FROM tblPages WHERE parentID = 0";
$getPID_result = mysql_query($getPID_sql);
if(!$getPID_result){print mysql_error()."<br />";}else{
    while ($row = mysql_fetch_array($getPID_result, MYSQL_ASSOC)) {
  $parentID = $row["pageID"];
  $linkName = $row["pageTitle"];
  $linkID = $row["pageID"];
  print "<A href = '".$pagename."?id=".$linkID."'>".$linkName."</A> | ";
  if($pageID){
    $subpages_sql = "SELECT * FROM tblPages WHERE parentID = $parentID";
    $subpages_results = mysql_query($subpages_sql);
    if(!$subpages_results){print mysql_error();}else{
        $rowcount = mysql_num_rows($subpages_results);
            if($rowcount > 0){
            while ($row2 = mysql_fetch_array($subpages_results, MYSQL_ASSOC)) {
            $sublinkName = $row2["pageTitle"];
            $sublinkID = $row2["pageID"];
            $sublinkParentID = $row2["parentID"];
            if($sublinkParentID == $pageID || $sublinkParentID == $PID){            
print "<a href='".$pagename."?id=".$sublinkID."'>".$sublinkName."</a>";
            }   
        }   
        }
    }       
    }
}
}
?>
4

1 回答 1

0
<?
$pagesrc = $_SERVER['SCRIPT_NAME'];
$getPID_sql = "SELECT * FROM tblPages WHERE parentID = 0";
$getPID_result = mysql_query($getPID_sql);
if(!$getPID_result){print mysql_error()."<br />";}else{
    while ($row = mysql_fetch_array($getPID_result, MYSQL_ASSOC)) {
  $parentID = $row["pageID"];
  $linkName = $row["pageTitle"];
  $linkID = $row["pageID"];
  print "<A href = '".$pagename."?id=".$linkID."'>".$linkName."</A> | ";
  if($pageID){
    $subpages_sql = "SELECT * FROM tblPages WHERE parentID = $parentID";
    $subpages_results = mysql_query($subpages_sql);
    if(!$subpages_results){print mysql_error();}else{
        $rowcount = mysql_num_rows($subpages_results);
            if($rowcount > 0){
                    echo "<div class='submenu'>"; //you can either give class or id whatever you want
            while ($row2 = mysql_fetch_array($subpages_results, MYSQL_ASSOC)) {
            $sublinkName = $row2["pageTitle"];
            $sublinkID = $row2["pageID"];
            $sublinkParentID = $row2["parentID"];
            if($sublinkParentID == $pageID || $sublinkParentID == $PID){            
print "<a href='".$pagename."?id=".$sublinkID."'>".$sublinkName."</a>";}   
        } 
            echo "</div>";  
        }
    }       
    }
}
}
?>

在需要的地方添加了标签

于 2012-12-15T05:52:55.927 回答