Welcome Guest, Not a member yet? Register   Sign In
Got empty results from model, even though there're data in database
#1

Hi Guys,

I am new to codeIgniter and I have a problem when working with models.

Database is setup fine and has some fake data on the table. However I can't access then.

My model
PHP Code:
class Site_model extends CI_Model {

    function 
getAll() {
        
$data = array();
        
$q $this->db->get('test');
        if (
$q->num_rows() > 0) {

            foreach (
$q->result() as $row) {
                
$data[] = $row;
            }
        }
        return 
$data;
    } 


My Controller
PHP Code:
class Site extends CI_Controller {

    public function 
__construct() {
        
parent::__construct();
    }

    public function 
index() {
        
$this->load->model('site_model');
        
$data['records'] = $this->site_model->getAll();
        
$this->load->view('home'$data);
        echo 
$data['records'];
    }




My View
PHP Code:
<html>
    <
head>
        <
title>title</title>
    </
head>
    <
body>
        <
div id="container">
            <
p>My View has been loaded</p>
        </
div>
        <
pre>
            <?
php print_r($records?>
        </pre>
    </body>
</html> 


And here is the results I got ( An empty array )

My View has been loaded

Array
(
)
Reply


Messages In This Thread
Got empty results from model, even though there're data in database - by gabrielpasv - 03-18-2015, 08:02 AM



Theme © iAndrew 2016 - Forum software by © MyBB