[eluser]Spleshmen[/eluser]
hello all.i am new to codeigniter and i am trying to learn how to use this framework
in the user guide i see all database examples are with foreach loops and i tried to make one with a while loop but its not working,maby you can tell me where i did wrong.thanks
here is my model (site_model.php):
Code:
<?php
class Site_Model extends Model {
function getAll() {
$data = array();
$query = $this->db->query("SELECT title,body FROM entries");
if ($query->num_rows>0)
while($row = $query->result() ) {
$data[] = $row;
}
return $data;
}
}
?>
here is my controler (site.php)
Code:
<?php
class Site extends Controller {
function index() {
$this->load->model('site_model');
$data['records'] = $this->site_model->getAll();
$this->load->view('home.php',$data);
}
}
?>
here is my view page (home.php)
Code:
<?php
foreach($records as $row) {
echo $row->title."<br>";
echo $row->body."<hr>";
}
?>
if i use a foreach loop in the model code then it works just fine else i get this error :
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 35 bytes) in ...
Thanks