从父ID php显示父菜单的子菜单

时间:2014-12-02 04:47:08

标签: php mysql

<?php
   $page= $objPage-> get_page(); 
   $id = isset($_GET['id']);
   $child= $objPage-> get_child_page($id);  
?>

     <ul class="nav nav-tabs">
        <li role="presentation" class="dropdown">
            <?php 
      while($row = mysql_fetch_array($page) ) { ?> 
<a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-  expanded="false">       
         <?php echo $row['title']; ?> <span class="caret"></span> 

         </a>       
           <?php } ?>
        </li>
    </ul>

功能get_page

function get_page($id="") {
 $sql = "SELECT "; if( !empty($field) ){ 
$sql .=" title FROM page WHERE page_id>1 " ; 
} else {
 $sql .= " * FROM page "; 
} 
if( !empty($id) ){ 
$sql .=" WHERE page_id=".$id; 
} else { 
$sql .=" WHERE parent_id= -1"; 
} 
$result = mysql_query($sql) or die( mysql_error() ); 
if( !empty($id) && $result ){ 
$value = mysql_fetch_array($result) ; 
return $value; 
} 
return $result; 
}

功能get_child_page

function get_child_page($id){ 
$sql = "SELECT * FROM page WHERE parent_id= $id"; 
$result = mysql_query($sql);
 return $result; 
}

我得到父菜单,其父ID为-1,但我想显示来自父ID的子菜单..任何解决方案??

0 个答案:

没有答案