做一个类似微博的程序,想知道怎样获取所有我收到的评论 我做一个类似新浪微博的程序,我想获取我收到的评论。因为评论有别人对我发的微博的评论,也有我去别人微博下面发的评论然后别人回复我的评论,请问怎样获取所有这些评论?现在数据表(评论表)有这样几个自字段 :id(评论id),uid(评论发布者),content(评论内容),wid(评论所属微博id) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 楼主是不是在做后盾微博的那个项目??我当时是这么改的,你可以参考我的代码注释。最后能够取出“我”发的评论和“我”收到的所有评论,代码如下: /** * 展示评论列表 */ public function comment(){ //重置缓存 set_msg(session('uid'), 1, true); //取出我发的微博的id $my_uid = session('uid'); $wids = M('weibo')->where(array('uid'=>$my_uid))->field('id')->select(); //取出我参与评论的微博的id $comment_db = M('comment'); $other_wids = $comment_db->where(array('uid'=>$my_uid))->field('wid AS id')->select(); //合并所有需要取出的微博id $wids = array_merge_recursive($wids, $other_wids); foreach($wids as $k=>$v){ $wids[$k] = $v['id']; } $wids = array_unique($wids); //合并后去重复 //根据wid取出comment表的id,uid,content,time等信息,再把comment表的id取出 $uids = $comment_db->where(array('wid'=>array('IN', $wids)))->select(); foreach($uids as $k=>$v){ $cids[$k] = $v['id']; } //根据comment表的id取出评论 $db = D('CommentView'); $where = array('comment.id'=>array('IN', $cids)); //分页 $count = $db->where($where)->count(); import('ORG.Util.Page'); $page = new Page($count, 10); $limit = $page->firstRow . ',' . $page->listRows; $comment = $db->where($where)->order('time DESC')->limit($limit)->select(); //分配变量到模板 $assign = array('count'=>$count, 'comment'=>$comment, 'page'=>$page->show()); $this->assign($assign); $this->display(); } 两种方式生成视频截图(共享给有需要的人) 复旦百能网-是不是专业IDC服务商? 没有看到好的源码 最近在自学dedecms。 php 判断是否在当前页面打开链接 AppServ 2.5.9下载后怎么也无法安装,求解答! 高分求教wordpress问题!!! ajax+PHP+MYSQL Discuz的跨域验证 将收到的POST数据,写入文本 要求用telnet来请求 编译php的时候,加入了oic8的支持却报错了,怎么改? ecshop
* 展示评论列表
*/
public function comment(){ //重置缓存
set_msg(session('uid'), 1, true); //取出我发的微博的id
$my_uid = session('uid');
$wids = M('weibo')->where(array('uid'=>$my_uid))->field('id')->select(); //取出我参与评论的微博的id
$comment_db = M('comment');
$other_wids = $comment_db->where(array('uid'=>$my_uid))->field('wid AS id')->select();
//合并所有需要取出的微博id
$wids = array_merge_recursive($wids, $other_wids);
foreach($wids as $k=>$v){
$wids[$k] = $v['id'];
}
$wids = array_unique($wids); //合并后去重复 //根据wid取出comment表的id,uid,content,time等信息,再把comment表的id取出
$uids = $comment_db->where(array('wid'=>array('IN', $wids)))->select();
foreach($uids as $k=>$v){
$cids[$k] = $v['id'];
}
//根据comment表的id取出评论
$db = D('CommentView');
$where = array('comment.id'=>array('IN', $cids)); //分页
$count = $db->where($where)->count();
import('ORG.Util.Page');
$page = new Page($count, 10);
$limit = $page->firstRow . ',' . $page->listRows; $comment = $db->where($where)->order('time DESC')->limit($limit)->select();
//分配变量到模板
$assign = array('count'=>$count, 'comment'=>$comment, 'page'=>$page->show());
$this->assign($assign);
$this->display();
}