Welcome Guest, Not a member yet? Register   Sign In
problem when using a while loop
#1

[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>";
}
?&gt;
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


Messages In This Thread
problem when using a while loop - by El Forum - 12-26-2009, 09:03 AM
problem when using a while loop - by El Forum - 12-26-2009, 09:36 AM
problem when using a while loop - by El Forum - 12-26-2009, 09:36 AM
problem when using a while loop - by El Forum - 12-26-2009, 09:52 AM
problem when using a while loop - by El Forum - 12-26-2009, 10:22 AM
problem when using a while loop - by El Forum - 12-26-2009, 10:33 AM



Theme © iAndrew 2016 - Forum software by © MyBB