若是QQ空间那种,这里无需再使用无限级分类。

而是帖子之下的评论回复使用字段标记分清从属后按时间排序就行

//根据回复评论表,查询出回复人和被回复人信息

select
acrr.id,comment_id,content,time,acrr.account_id,type,mi.name as mename,mi.p_w_picpath as mimg,
do.name as doname,do.p_w_picpath as dimg,replied_account_id,rtype,(select name from ll_member_info where account_id=replied_account_id) as rmename,
(select name from ll_doctor_info where account_id=replied_account_id) as rdoname,
(select p_w_picpath from ll_member_info where account_id=replied_account_id) as rmimg,
(select p_w_picpath from ll_doctor_info where account_id=replied_account_id) as rdimg
from
ll_article_comment_reply_record as acrr
left join ll_member_info as mi on acrr.account_id=mi.account_id
left join ll_doctor_info as do on acrr.account_id=do.account_id
where
article_id=$article_id
AND comment_id=$cid
order by time asc

无限级分类:一个分类型可以有无限个分类

常见的无限分类实现

商品分类,子类导航,贴吧回帖

//=====1.递归方式实现无限级分类======

原理:每个分类都需记录它的父级id,当为顶级分类时,父级id为0.每个分类都可通过父级id一层层查明它所在父级,以便知道它所属分类,层级深度为几。

递归——自己调用自身(一定要有判断)?

储存结果的变量迭代方法

function getList(&$i=1){

echo $i.'<br/>';

$i++;

if($i<20){

getList($i);

}

}

getList();

$i=1;

function getList(){

global $i;

echo $i.'<br/>';

$i++;

if($i<20){

getList($i);

}

}

getList();

function getList(){

static $i=1;

echo $i.'<br/>';

$i++;

if($i<20){

getList($i);

}

}

getList();

总结:

self::getList($row['id'],$result,$spac);不断递归pid

$sql='select * from imooc where pid='.$pid;不断按需要调整条件查询

function getList($pid=0,&$result=array(),$spac=0)  $result[]=$row;不断迭代

当使用迭代去除所有数据时,是怎样区分ta分级的。

getList($pid=0,&$result=array(),$spac=0)

用这个表示区分层数,每次调用都是new出新栈独立运算

//=====2.全路径无限分类:以一个字段把它所有父级ID按顺序记录下来=====

总结:

$sql="select id,catename,path,concat(path,',',id) as fullpath from imooc order by fullpath asc";

他在order by的时候就已经将序列搞好了

区分深度

$deep=count(explode(',', trim($row['fullpath'],',')));

///无限级分类_代码展示

<?
/** Author:Abo* Date:2015/7/27*/
/*
变成下拉列表
从pid=0递归下去
*/
class toList{public static $mysqli;function conn(){$mysqli=new mysqli('localhost','root','','test');$mysqli->query('set names utf8');if(!$mysqli) die("连接数据库失败".$mysqli->connect_error());return $mysqli;}function getList($pid=0,&$result=array(),$spac=0){$spac=$spac+4;$mysqli=self::conn();$sql='select * from imooc where pid='.$pid;$res=$mysqli->query($sql);while ($row=$res->fetch_assoc()) {$row['catename']=str_repeat(' ', $spac).'|--'.$row['catename'];$result[]=$row;self::getList($row['id'],$result,$spac);             //递归}return $result;if($mysqli!=null) $mysqli->close();}
}
/*
按要求封装数据,变成下拉列表
*/
function displayCate($pid = 0, $selected = 0) {$ts = new toList ();$ts->conn ();$rs = $ts->getList ();$temp=null;$str="<select name='cate'>";foreach ( $rs as $val ) {$temp=null;if($val['id']==$selected){echo $val['id'];$temp="selected='selected'";}    $str.="<option $temp >".$val ['catename'].'</option>';}$str.='</select>';return $str;
}
header("Content-Type: text/html;charset=utf8");
echo displayCate(0,2);/*
变成导航栏
从pid=10递归上来再倒序
*/
class toList{public $host='localhost';public $username='root';public $password='';public $db='test';function conn(){$mysqli=new mysqli($this->host,$this->username,$this->password,$this->db);$mysqli->query('set names utf8');if(!$mysqli) die('数据库连接失败'.$mysqli->connect_error);return $mysqli;    }function getList($id,&$result=array()){$sql='select * from imooc where id='.$id;$mysqli=self::conn();$res=$mysqli->query($sql);if($row=$res->fetch_assoc()){$result[]=$row;self::getList($row['pid'],$result);}return $result;}
}$ts=new toList();
$rs=$ts->getList(10);
/*
按要求封装变成地址导航
*/echo krsort($rs);header("Content-Type: text/html;charset=utf8");
echo '<pre>';
print_r($rs);//===============================全路径无限分类==================================
/*
下拉列表
*/
class toList{public $host='localhost';public $username='root';public $password='';public $db='test';function conn(){$mysqli=new mysqli($this->host,$this->username,$this->password,$this->db);$mysqli->query('set names utf8');if(!$mysqli) die('数据库连接失败'.$mysqli->connect_error);return $mysqli;}function getList(){$sql="select id,catename,path,concat(path,',',id) as fullpath from imooc order by fullpath asc";$mysqli=self::conn();$res=$mysqli->query($sql);$result=array();while($row=$res->fetch_assoc()){$deep=count(explode(',', trim($row['fullpath'],',')));$row['catename']=str_repeat(' ', $deep).'|--'.$row['catename'];    $result[]=$row;
//             self::getList($row['pid'],$result);}return $result;}
}$ts=new toList();
$rs=$ts->getList();header("Content-Type: text/html;charset=utf8");
$str="<select name='cate'>";
foreach ($rs as $val){$str.='<option>'.$val['catename'].'<option>';
}
$str.="</select>";echo $str;class toList{public $host='localhost';public $username='root';public $password='';public $db='test';function conn(){$mysqli=new mysqli($this->host,$this->username,$this->password,$this->db);$mysqli->query('set names utf8');if(!$mysqli) die('数据库连接失败'.$mysqli->connect_error);return $mysqli;}function getList($cateid){$sql="select * ,concat(path,',',id) fullpath from imooc where id= $cateid";$mysqli=self::conn();$res=$mysqli->query($sql);$row=$res->fetch_assoc();$ids = $row['fullpath'];$sql="select * from imooc where id in ($ids) order by id asc";$res=$mysqli->query($sql);$result=array();while($row=$res->fetch_assoc()){$deep=count(explode(',', trim($row['fullpath'],',')));$row['catename']=str_repeat(' ', $deep).'|--'.$row['catename'];    $result[]=$row;
//             self::getList($row['pid'],$result);}return $result;}
}$ts=new toList();
$rs=$ts->getList(4);
echo '<pre>';
print_r($rs);
header("Content-Type: text/html;charset=utf8");
// $str="<select name='cate'>";
/*
按要求封装变成地址导航
*/
foreach ($rs as $val){echo "<a href=''>".$val['catename']."</a>>";
}

转载于:https://blog.51cto.com/minabo/1719883

帖子回复——无限级分类相关推荐

  1. jquery实现层级显示 效果图_php运用无限级分类实现评论及回复功能

    经常在各大论坛或新闻板块详情页面下边看到评论功能,当然不单单是直接发表评论内容那么简单,可以对别人的评论进行回复,别人又可以对你的回复再次评论或回复,如此反复,理论上可以说是没有休止; 从技术角度分析 ...

  2. Python实现无限级分类

    1.什么是无限级分类? 顾名思义,就是一级接一级的无限制分级.其实简单点说就是一个人类可以繁衍出多个后代,然后一个后代又可以分另外多个后代这样无限繁衍下去(举例:家族族谱),就好象linux系统你可以 ...

  3. php查找顶级分类,php 无限级分类 获取顶级分类ID,php顶级_PHP教程

    php 无限级分类 获取顶级分类ID,php顶级 有这样一个表,id是分类的ID,name是分类名称,pid是上级分类的ID. 现在有个分类ID,程序要找到它上级的上级的上级--分类的ID,简单说就是 ...

  4. “大一新生如何参加智能车比赛”帖子回复

      在论坛水了两三年了,见到了不少大佬非常厉害的开源设计,也算是这个论坛( ZNCZZ )的忠实受益者之一.   这篇帖子是搬运我在知乎一个问题,"大一新生如何参加智能车比赛"下面 ...

  5. 无限级分类实现思路 (组织树的分级管理)

    2019独角兽企业重金招聘Python工程师标准>>> 关于该问题,暂时自己还没有深入研究,在网上找到几种解决方案,各有优缺点. 第一种方案: 使用递归算法,也是使用频率最多的,大部 ...

  6. .net简单算法实现无限级分类(一)

    在项目中我们往往需要实现无限级分类,而网上的.NET的例子不是很多,asp的倒是不少,这个算法是我根据网上的asp的例子在结合.net中的TREEVIEW控件来实现多级甚至无限级分类.      对于 ...

  7. php修改新闻分类代码,完整的新闻无限级分类代码,可添加,删除,移动,修改

    //连接数据库教程 $link = mysql教程_connect('localhost','root','密码') or die(mysql_error()); mysql_select_db('s ...

  8. 迭代与递归实现无限级分类

    无限级分类是开发中常见的情况了,在这里我收藏了下并整理了下常见的无限极分类算法总结归纳. <?php $arr = [1=>['id'=>1,'name'=>'家居','fat ...

  9. ASP.NET 无限级分类实现实例(深度字段)

    下图中红色箭头是父类 而且属于根目录级别. 下面个字段为:ID 父ID 类型名称 深度 排序 前面3个字段没有什么可解释的,做过无限级分类设计的人都应该清楚 而第5个字段排序字段ID:43的23排序代 ...

最新文章

  1. Shell脚本笔记(三)shell中的数学计算
  2. 设计模式之 - 简单工厂模式
  3. 一个基于 Spring Boot 的项目骨架,少造轮子!
  4. linux中here文档,Linux下Bash Heredoc(Here document)的用法及基本示例
  5. thinkpad笔记本散热风扇_十代酷睿笔记本低至2999元 你可以入手了_笔记本新闻
  6. 概率论与数理统计思维导图知识框架_考研概率论与数理统计 综合题型秘籍思维导图① 随机变量1~3章 [21考研上岸之旅]...
  7. Chrome 爬虫插件 Web Scraper
  8. java异常处理机制_Java的异常处理机制
  9. Java是世界上最好的语言!
  10. Nodejs 4.0 ES6特性
  11. MATLAB模糊控制算法,驾驶员制动意图识别,Fuzzy模糊控制算法,试验案例+模型+模糊控制器
  12. ora 01033 linux,ORA-01033: ORACLE initialization or shutdown in progres
  13. b站的视频如何下载到手机上
  14. 对权力说真话:CEO萨蒂亚•纳德拉与微软的三两事
  15. 【智能家居】空调遥控器破解
  16. Mac自启动程序管理
  17. 隐私保护模型之——语义匿名模型
  18. ATFX:新西兰联储加息50基点,NZDUSD先涨后跌
  19. 利用matlab实现三体问题(双星、3星、多星运动)
  20. Docker学习1-基本命令

热门文章

  1. root用户连接mysql数据库出错 1045 access denied for user 'root'@'localhost' using password yes
  2. mysql identity sql,SQL Server的Identity字段使用/复制/重设
  3. cron表达式 每天0点10分和30分_查找特定时间段cron任务方法
  4. ASP.NET Core 入门教程 8、ASP.NET Core + Entity Framework Core 数据访问入门
  5. Oracle BI11启动失败
  6. IOS中单例的简单使用
  7. A站有一个页面需要PV统计 A站读写该数据 B站读该数据 需要数据同步
  8. Keil uVision4 for ARM 下增加支持C51,C5x
  9. 编译cubieboard android 源码过程详解之(六):pack
  10. OpenSSL命令---pkcs7