(01-15-2018, 02:35 AM)neuron Wrote: Can you share you comments and posts table structure;
Also there are mistakes in your get comments query:
Instead of
$this->db->select('*');
$this->db->from('comments');
$this->db->where('comments', array('slug' => $slug));
$this->db->join('comments', 'comments.id = posts.id');
change to
$this->db->select('*');
$this->db->from('comments');
$this->db->join('comments', 'comments.id = posts.id');
$this->db->where(array('slug' => $slug));
$query = $this->db->get();
where clause comes after join;
and what is "posts.id" in your query?
This is my POSTS table in DB:
This is my COMMENTS table in database:
and this is my full code to "get" the comments for each post(Post_model).
PHP Code:
// Comments
public function get_post_comments($slug){
$this->db->select('username,email,website,body');
$this->db->from('comments');
$this->db->join('comments', 'comments.id = posts.id');
$this->db->where(array('slug' => $slug));
$query = $this->db->get();
if($query->num_rows() >= 1){
return $query->result();
} else {
return false;
}
}
I do Front-End development most of the time