I am having problems returning desired results from my database, the script is been run from within a class as follows.
class news {
// declare variables
var $record;
var $id;
var $startdate;
var $title;
var $description;
var $count;
// build constructor
function News( $Trecord = "", $Tid = "", $Tstartdate = "", $Ttitle = "", $Tdescription = "", $Tcount = ""){
$record = $Trecord;
$id = $Tid;
$startdate = $Tstartdate;
$title = $Ttitle;
$description = $Tdescription;
$count = $Tcount;
}
// methods
function return_id(){
return $this->id[$this->record];
}
function return_startdate(){
return $this->startdate[$this->record];
}
function return_title(){
return $this->title[$this->record];
}
function return_description(){
return $this->description[$this->record];
}
function record($recnum){
$this->record = $recnum;
}
function reset(){
$this->record =0;
}
function getnews(){
mysql_connect("localhost", "root");
$db = mysql_select_db("ims");
$sql = "SELECT C.ID as ID,
C.Title as Title,
C.Description as Description,
C.StartDate as StartDate,
C.EndDate as EndDate,
C.TimeStamp as TimeStamp
FROM content C,
subsection SS,
section S
WHERE S.SectionName = 'Add/Edit Content'
AND SS.SubSectionName = 'Latest News'
AND SS.SectionID = S.ID
AND C.SubSectionID = SS.ID
ORDER BY
C.StartDate, C.TimeStamp DESC";
$qry = mysql_query($sql,$db);
$this->count = mysql_num_rows($qry);
/*if (mysql_num_rows($qry) == 0) {
echo "no records found";
die;
} else {*/
$i=0;
while($rec = mysql_fetch_array($qry)) {
$this->id[$i] = $rec['ID'];
$this->description[$i] = $rec['Description'];
$this->title[$i] = $rec['Title'];
$i++;
}
// }
}
function get_count() {
return $this->count;
}
} // end class
// output the results
$row = new news();
$row->getnews();
$count = $row->get_count();
echo "count = $count<Br>";
for($r=0; $r<$count; $r++) {
$row->record($r);
$row_id = $row->return_id();
$row_description = $row->return_description();
echo "Record $r : id = $row_id - descripion = $row_description<br>";
}
I have ran the SQL directly and it does return results. is there a better way to make a database connection ??
Cheers for any help folks.