How to prepare a model to return json_encode data in Codeigniter framework

Here we are fetching data of the projects table and showing returning it in json format.

public function projectData() {
    $result = array();  
    $data = $this->db->get_where("projects")->result();
    foreach ($data as $row) {
        $result[] = array("myid" => $row->id, "project_name" => $row->project_name, "description"->$row->description);
    }
    return json_encode($result);
}

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.