Hi All
This is the class that I have created (news.php)....
class News {
var $_DB = FALSE;
var $_NewsTable = "news";
var $ErrorMessage = FALSE;
function News(&$DB){
$this->_DB = &$DB;
}
function showNews(){
$output .= '
<table cellspacing=0 cellpadding=0 width=80% align=center>
<tr class=baseFont><td><b>Latest News</b></</td></tr>
<tr><td background="images/dots.gif"></td></tr>
';
$query = "SELECT * FROM ".$this->_NewsTable." WHERE active = 'Y' ORDER BY date DESC";
$result = $db->query($querySel);
$rowNum = $result->numRows();
if(!DB::isError($result)) {
if($rowNum=='0'){
$output .= '<tr class=baseFont><td>Currently No News Available</td></tr>';
}
while($row = $result->fetchrow()){
$output .= '
<tr><td height=5></td></tr>
<tr class=baseFont><td><b>'.stripslashes($row->title).'</b></td></tr>
<tr class=baseFont><td><font color=gray>Date: '.stripslashes($row->date).' | Time: '.stripslashes($row->time).'</font></td></tr>
<tr class=baseFont><td>'.stripslashes($row->text).'</td></tr>
<tr><td height=5></td></tr>
<tr><td background="images/dots.gif"></td></tr>
';
}
$output .= '</table>';
} else {
$this->ErrorMessage = "We have encountered an error";
}
}
function status() {
return $this->ErrorMessage;
}
}
and this is the code that calls the class (show.php)...
include 'DB_INFO.php';
include 'news.php';
$news = new News($db);
$news->showNews();
echo $news->status();
When I call the class, I get this error ...
Fatal error: Call to a member function on a non-object in C:\webfiles\CODE SNIPPETS\News Items\news.php on line 19
Is this a problem with the class itself, or a problem with DB_INFO.php that contains the DB connection (i have included it below) ...
/*
This file is used for Database Setup.
Pretty self explanitary, replace the values below with your corresponding mySQL values.
Note!
The "table name" is defined in the Authentication.php class.
*/
require_once 'DB.php';
$username = "root"; // Put your username here
$password = "qr8t0r"; // Put your password here
$host = "localhost"; // Put the IP address or hostname of your mySQL server here.
$db_name = "catmandu_co_za"; // Put your database name here.
$dsn = "mysql://$username:$password@$host/$db_name";
$db = DB::connect($dsn, true);
$db->setFetchMode(DB_FETCHMODE_OBJECT);
if (DB::isError($db)) {
die ($db->getMessage());
}
global $db;