This is not working:

class Post extends CI_Model{

    function get_posts($num=20, $start=0){
        //$sql="SELECT * FROM users WHERE active=1 ORDER BY date_added DESC LIMIT 0,20;";
        $this->db->select()->from('posts')->where('active',1)->order_by('date_added','desc')->limit($num, $start);
        $query=$this->db->get();
        return $query->result_array();
    }
}

and giving me a:

[20-Jun-2013 17:42:21] PHP Fatal error: Call to a member function select() on a non-object in public_html/codeigniter/application/models/post.php on line 7

and

A PHP Error was encountered

Severity: Notice

Message: Undefined property: Posts::$db

Filename: core/Model.php

Line Number: 51

Try:

$this->db->where('active',1)->order_by('date_added','desc')->limit($num, $start)->get('posts');

When selecting all the fields, the select() method is not needed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.