I am trying to return json data using codeigniter which I will later use that json in javascript. Now the problem is that it only returns the last row from database table and make a json format from that one row. Here is my code in controller
public function v1 () {
$this->load->model('model_jokes');
$jokes = $this->model_jokes->readJokes();
foreach ($jokes as $joke) {
$arr = array(
array(
'title' => $joke->title,
'description' => $joke->joke
)
);
}
echo json_encode($arr);
}
how can I make it so that all data that I am retrieving from database is returned in json?