gpt4 book ai didi

php - 从 mysql 获取主类别的子类别

转载 作者:行者123 更新时间:2023-11-29 13:32:36 24 4
gpt4 key购买 nike

我在从 mysql 数据库检索子类别时遇到一些问题。我想显示父类别的子类别。我只能获取主类别的最后一个子类别。第一个子类别不显示**。在我的表中**我有category_id和category_parent_id。其中父类别的category_parent_id将为“0”。。提前致谢

 <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 ")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['category_id'].$row['name_en-GB'];

$result1=mysql_query("select * from table where category_parent_id=".$category_id)or die("No data available with this name"."<br/><br/>".mysql_error());
echo $num_row = mysql_num_rows($result1);

if($num_row>0) {
for($i=0;$i<$num_row;$i++)
{
while($row1=mysql_fetch_array($result1))
{

?>
<ul style="margin:0px;padding:0;">
<li><?php echo $row1['name_en-GB']?></li>
</ul>
<?php
}
}
}

?>


</li>

<?php } ?>



<?php }?>
</ul>

当我删除<li>时标签位于末尾,并将其保留在 in 末尾,虽然我可以显示所有子类别,但 css 并不适用于此。那里出了点问题,但我无法弄清楚

最佳答案

删除以下内容并重试:

for($i=0;$i<$num_row;$i++)
{

关于php - 从 mysql 获取主类别的子类别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19196680/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com