i have two table, one is post table and other one is comment table.in which i am using post_id as foreign_key. Now i want to get, a post with all its comments. and response should be in this format.
{
"posid":1,
"post_name":"testpost",
"comments":[{
"comment_id":1,
"comment_des":"testcoment"
},{
"comment_id":2,
"comment_des":"testcoment2"
}
]
}
Can any one write simple SQL query for me for this type of response?
I tried below query in codeigniter , but this return multiple result, mean one post two time, because one post contains two comments.
$this->db->select("p.post_id,p.post_desc,p.post_time ,c.id,c.comment_desc,c.comment_time");
$this->db->join("asoc_comments as c","p.post_id = c.post_id","INNER");
$response = $this->db->get("asgn_posts as p")->result();