Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我想使用codeigniter对每个帖子发表所有评论_Php_Mysql_Html_Codeigniter_Forum - Fatal编程技术网

Php 我想使用codeigniter对每个帖子发表所有评论

Php 我想使用codeigniter对每个帖子发表所有评论,php,mysql,html,codeigniter,forum,Php,Mysql,Html,Codeigniter,Forum,图中显示了我希望显示每个帖子所有评论的所有帖子。我用红色标记了评论部分` public function forum(){ $config['base_url'] = site_url('tourism_con/forum'); $config['total_rows'] = $this->db->get('forum_posts')->num_rows(); $config['uri_segment'] = 3; $config['per_

图中显示了我希望显示每个帖子所有评论的所有帖子。我用红色标记了评论部分`

public function forum(){
    $config['base_url'] = site_url('tourism_con/forum');  
    $config['total_rows'] = $this->db->get('forum_posts')->num_rows();
    $config['uri_segment'] = 3;
    $config['per_page'] = 5; 
    $config['full_tag_open'] = "<ul class='pagination pagination-lg'>";
    $config['full_tag_close'] ="</ul>";
    $config['num_tag_open'] = "<li>";
    $config['num_tag_close'] = '</li>';
    $config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
    $config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
    $config['next_tag_open'] = "<li>";
    $config['next_tagl_close'] = "</li>";
    $config['prev_tag_open'] = "<li>";
    $config['prev_tagl_close'] = "</li>";
    $config['first_tag_open'] = "<li>";
    $config['first_tagl_close'] = "</li>";
    $config['last_tag_open'] = "<li>";
    $config['last_tagl_close'] = "</li>";
    $data['forum_title']='Forum :: Home Page';
    $data['forumPosts']='forumPosts';
    $data['forum_details']=  $this->tourism_model->get_forum_post($config);
    $data['comment_count']=$this->tourism_model->get_comments_by_post();
    $this->load->view('Forum/forum_home',$data);
}
下面是模型中注释的代码,用于从数据库检索注释

public function get_comments_by_post(){
   $this->db->select('comment_id');
   $this->db->distinct();
   $this->db->from('comment');
   $query = $this->db->get();
   return $query->num_rows();
}
查看代码部分



作者:
发布于


get\u comments\u by\u post
功能中执行此操作:过去
post\u id

public function get_comments_by_post($postid){
    $q = $this->db->query("SELECT * FROM comments WHERE post_id = $postid");
    if($q->num_rows() > 0) {
        return $q->result_array();
    } else {
        return '';
    }
}

然后使用
post\u id
作为标准选择您的评论,所有帖子一起从数据库中检索。我如何将post\u id从这些帖子中分离出来?如果不知道您的数据库结构post table和comment table,这个问题是无法回答的,因为它们是两个不同的表。因此,每当我需要数据时,我都会在这两个表上应用查询tables.it's not work.it show A PHP Error遇到严重性:错误消息:无法将stdClass类型的对象用作数组文件名:models/tourism\u model.PHP行号:144$all_posts[$i]['comment']=$this->get_comments\u by_post($all_posts[$i]['post\u id')$数据['forum\u details']=$this->tourism\u model->get\u forum\u post($config);在$data['forum\u details']中存储所有帖子信息。现在您只需告诉我如何将帖子id从数组中分离出来。然后我会将帖子id发送到model,它会发回每篇帖子的评论总数。@hmamun您可以发布
$data['forum\u details']
中的帖子吗,我将告诉您如何检索
post\u id
public function get_comments_by_post($postid){
    $q = $this->db->query("SELECT * FROM comments WHERE post_id = $postid");
    if($q->num_rows() > 0) {
        return $q->result_array();
    } else {
        return '';
    }
}