Hi guys i am quite new to classes in PHP
What i have is this class
class DbConnector extends SystemComponent {
var $theQuery;
var $link;
function DbConnector(){
//Load the values from SystemComponent $settings;
$settings = SystemComponent::getSettings();
$host= $settings['dbhost'];
$db = $settings['dbname'];
$user = $settings['dbusername'];
$pass = "";
//Connect to the db
$this->link = mysql_connect($host,$user,$pass);
mysql_select_db($db);
register_shutdown_function(array(&$this,'close'));
}
///Perform a query
function query($query){
$this->theQuery = $query;
return mysql_query($query, $this->link);
}
///Retrieve values
function fetchArray($result){
return mysql_fetch_array($result);
}
function getResults($result){
while(mysql_fetch_array($result)){
$i = 0;
//amount of rows in db
$NumRows = mysql_num_rows($result);
while ($i < $NumRows){
return(mysql_fetch_array($result));
return($NumRows);
$i++;
}
}
}
///Close the MYSQL connection
function close(){
mysql_close($this->link);
}
Now what im trying to do is retrive all results from a query in the main php page to display all entries in the database. It works fine when trying to retrieve 1 value but when i try to retrieve all values to display in the page it only will show the last entry not all the previous ones. :S
The code from the page calling this class.
require_once('includes/QueryProcessor.php');
$connector = new DbConnector();
$result = $connector->query('SELECT * FROM welcome');
$row = $connector->getResults($result);
echo "NumRows is ".$connector->getResults['$NumRows'];
echo"<br />".$row['Title'];
Any help would be appreciated.
Many Thanks Pinky. 🙂