0

I have never looked into classes at all so I'm just learning right now.

But like always I got troubles before I've even started -.-

class news { 
    public $countNews; 
    public $db;

    public function __construct() { 
        global $_database;
        $this->$db = $_database; 
    }
    public function countNews() { 
        return $this->$db->query("SELECT * FROM ".PREFIX."news ORDER BY date DESC")->num_rows; 
    }
}

This is my code right now, on this example im trying to count news. but it doesn't go to well if i say it like that.

My error right now is:

Notice: Undefined variable: db in news.class.php on line 11

Anyone that knows what I'm doing wrong and maybe can point me in the right direction?

Machavity
  • 30,841
  • 27
  • 92
  • 100
Tommy
  • 667
  • 1
  • 10
  • 25

0 Answers0