我想创建一个包含类别的列表,并将鼠标悬停在我需要显示子类别的类别上。我能够在列表中显示父类别。但无法理解如何获取子类别。在我的表中,我有 category_id、parent_id 列和其他一些列。如果 parent_id 为“0”,则它是主要类别,对于子类别,它包含 category_id。所以现在我需要显示主要类别的子类别。我不明白如何继续。任何人都可以提供建议。
<ul class="betterList">
<?php
$con = mysql_connect("localhost","root","pwd") or die('couldnot connect to database'.mysql_error());
mysql_select_db("DB",$con);
$result=mysql_query("select * from table order by `name_en-GB`")or die("No table available with this name"."<br/><br/>".mysql_error());
while($row=mysql_fetch_array($result))
{
$parent_id=$row['category_parent_id'];
$category_id=$row['category_id'];
if($parent_id==0)
{
?>
<li><?php echo $row['name_en-GB'];?></li>
<?php }
?>
<ul id="internal" style=" margin:0px;
padding:0;"><li><?php //echo $row['name_en-GB']; ?></li><li>data</li></ul></li>
<?php
}?>
</ul>