Thanks for the response, but your code is only getting the first row of the result....
lastRow is global for now, I might change it, I am not done with this class and I may call it into other functions, haven't decided yet. It is returned, because that is what the function returns...not sure what you mean by that.
But just to clear things up I am posting my entire class and how I am using it..
Everything in the class works fine except the getLastRow() and getAnyRow ()functions.
class dbConTran{
var $con;
var $numRows;
var $result;
var $resultArray;
var $firstRow = array();
var $lastRow = array();
var $anyRow = array();
// Open Database connection ---------
function dbOpen($name,$host,$user,$password){
$this->con = @mysql_connect($host, $user, $password)or die ("Error Connecting to Database!");
@mysql_select_db($name, $this->con) or die ("Error Selecting Database!");
}//end dbOpen
// Close Database Connection --------
function dbClose(){
@mysql_close($this->con);
}//end dbClose
// INSERT, UPDATE or DELETE from Database --------
function dbIUD($sql){
$this->result = @mysql_query($sql);
if(!$this->result){
return false;
}else{
return true;
}//end if
}//end dbIUD
// SELECT FROM Database --------
function dbSelect($sql){
$this->result = @mysql_query($sql);
$this->numRows = @mysql_num_rows($this->result);
if(!$this->result){
return false;
}else{
return true;
}//end if
}//end dbSelect
// Get first row of dbSelect --------
function getFirstRow(){
$this->firstRow = mysql_fetch_array($this->result);
return $this->firstRow;
}//end getFirstRow
// Get last row of dbSelect --------
function getLastRow(){
$this->lastRow = @mysql_data_seek($this->result,$this->numRows-1);
return $this->lastRow;
}//end getLastRow
// Get any row of dbSelect --------
function getAnyRow($rowNum){
if($rowNum > $this->numRows){
return false;
}else{
$this->anyRow = @mysql_data_seek($this->result,$rowNum);
return $this->anyRow;
}//end if
}//end getLastRow
// Get number of rows from dbSelect --------
function getNumRows(){
return $this->numRows;
}//end getNumRows
}// End Of Database Class -------------------------------
And here is how I'm using it
$db = new dbConTran();
$sql ="SELECT * FROM tblBooks";
$Database = "name";
$Hostname = "localhost";
$Username = "user";
$Password = "pass";
$db->dbOpen($Database,$Hostname,$Username,$Password);
$db->dbSelect($sql);
echo $db->getNumRows()."<br>";
$firstRow = $db->getFirstRow();
echo $firstRow['AuthorName']."<br>";
$lastRow = $db->getLastRow();
echo $lastRow['AuthorName']."<br>";
$db->dbClose();
Thanks for the help!