This is a complete n00b question but I cannot figure out what is wrong. As i have a class doing pretty much the same as what is happening in the error that's working :S
Fatal error: Call to a member function num_rows() on a non-object.
class basket
{
private $items;
private $quantity;
private $database;
private $error;
public static $instance;
private function __construct()
{
//create an instance of the database class and connect to the database
$this->database = database::getinstance();
//load the session items into the property $this->items
$this->items = $_SESSION['items'];
//set the standard error
$this->error = 'Product Does Not Exist!';
}
public function getinstance()
{
if(self::$instance === null)
{
$c = __CLASS__;
self::$instance = new $c;
}
return self::$instance;
}
public function add($id)
{
if ($this->items[$id] <= 0)
{
$this->items[$id] = 0;
}
if (ereg("([A-Z0-9]+)", $id))
{
$results = $this->database->query("SELECT * FROM `products` WHERE code='$id'");
//line 52 - Fatal error: Call to a member function num_rows() on a non-object
if ($results->num_rows() == 1)
{
$this->items[$id]++;
}
else
{
return $this->error;
}
}
else
{
return $this->error;
}
}
private function __destruct()
{
$_SESSION['items'] = $this->items;
}
//note: I didn't include all the class as it just hinders the problem