This class is for querying the db and returning result:
Code: Select all
<?php
//QUERY CLASS TEST
mysql_connect('localhost','','');
mysql_select_db(database);
class TESTQUERY{
public $query;
public $row;
public $loopdata;
private $result;
function query(){
$this->result=mysql_query($this->query) or die (mysql_error());
if(!mysql_numrows($this->result)){
echo "There is no information available.";
} else {
$this->row=mysql_fetch_assoc($this->result);
}
}
function loop(){
$this->result=mysql_query($this->query) or die (mysql_error());
if(!mysql_numrows($this->result)){
echo "There is no information available.";
} else {
while($this->row=mysql_fetch_assoc($this->result)){
return $this->loopdata;
}
}
}
}
//Single Row
$people=new TESTQUERY;
$people->query="SELECT people_fname FROM people WHERE people_id='$id'";
$people->query();
echo $people->row['people_fname']."<br />";
//Loop
$thing=new TESTQUERY;
$thing->query="SELECT people_fname FROM people";
$thing->loop();
echo $thing->loopdata=$thing->row['people_fname'];
?>