脚本宝典收集整理的这篇文章主要介绍了PHP使用递归生成文章树,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
因为自己的一个技术站,以文章为主,文章有些是一个系列的,所以想把这些文章归类,同一类的在一个下面。
数据库好设计,无非用id,fatherid来进行归类,fatherid代表父类是那篇文章的id,id是文章的唯一id,层次不限,可以是两层,可以是三层。fatherid为0的表示顶层文章。
connect(); $sql = "SELECT id,tITle,url From ".TABLE_TASK." WHERE fatherid=$fatherid and ispublic=1 order by id asc"; $articles = $db->query($sql); $db->close(); while ($record = $db->fetch_array($articles)){ $i = 0; if ($i == 0){ if($fatherid==0){ echo '
}
if($fatherid==0){
echo '<li><span class="glyphicon glyphicon-LOG-in"
aria-hidden="true" id="han'.$record['id'].'"&gt;
</span><a href="'.$record['url'].'" target="_blank">'
. $record['title'].'</a>';
}else{
echo '<li><span class="glyphicon glyphicon-chevron-right" aria-hidden="true">
</span><a href="'.$record['url'].'" target="_blank">'
. $record['title'].'</a>';
}
category_tree($record['id']);
echo '</li>';
$i++;
if ($i > 0){
echo '</ul>';
}
}
}
以上是脚本宝典为你收集整理的PHP使用递归生成文章树全部内容,希望文章能够帮你解决PHP使用递归生成文章树所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。