You are here: Class/Function Query Call Problem « PHP « IT news, forums, messages
Class/Function Query Call Problem

Posted by Chuck Brockman on 07/21/05 14:57

I'm creating a psuedo mail/message app for users to send messages to
one another. For this, I've created a parent class,
class.members.php, and an extended class, class.mail.php. The problem
I'm having is when I make page which calls the classes members and
memberMail creates an infite loop; however, if I bypass the classes
and do the mysqli functions directly on the page, I get the right
output. There is only one record in the database; fnGetMailCount()
produces one record and fnGetMail() using 'return $query->num_rows'
produces one record. I'm assuming there's something with my while
loop, but I've used
this method for other query output without issue.

One other note, I've also tested by removing all session variables and
hard coding values instead and received the same results. Also, the
database variables are stored in an array in _global.php which is
included in the output page.

I apologize if these are basic questions, but while I'm learning, I
would prefer to learn properly instead of coding a bunch of junk just
for the sake of getting it done quickly (please let me know if I'm
heading down that path).

Under class.members.php I've created the constructor to initialize the
database vars.

class members {
var $iMemberID;
var $iProfileID;
var $_iMemberID;
var $_iProfileID;
var $mysqli;
var $query;

function members($dbServer, $dbUser, $dbPassword,$dbDSN){
$this->_dbServer = $dbServer;
$this->_dbUser = $dbUser;
$this->_dbPassword = $dbPassword;
$this->_dbDSN = $dbDSN;
}
[...]
}


Under class.mail.php I've extended members():

class memberMail extends members {
var $iMailID;

function memberMail(){
parent::members();
}

function fnGetMailCount() {
$sql = "
SELECT iMessageID
FROM tblEmail
WHERE iToMemberID = ". $this->getMemberID();

$mysqli = new mysqli($this->_dbServer,
$this->_dbUser,$this->_dbPassword, $this->_dbDSN);
$query = $mysqli->query($sql);
return $query->num_rows;
}

function fnGetMail() {
$sql = "
SELECT *
FROM tblEmail
WHERE iToMemberID = ". $this->getMemberID() ."
Order by dtEmailDate Desc";

$mysqli = new mysqli($this->_dbServer, $this->_dbUser,
$this->_dbPassword, $this->_dbDSN);
$query = $mysqli->query($sql);
return $query->fetch_object();
//return $query->num_rows;
//return $query->fetch_assoc();
}
[....]
}


Output/calling page:

<?
require_once("../../classes/class.members.php");
require_once("../../classes/class.mail.php");

session_start();

require_once("../../_global.php");

//$objMember = new members(); //intialize member class

$objMail = new memberMail(); //initialize memberMail class
$objMail->members($aSiteSettings["sDBServer"],$aSiteSettings["sDBLogin"],$aSiteSettings["sDBPassword"],
$aSiteSettings["sDSN"]);
$objMail->setMemberID($_SESSION["iMemberID"]);
$iMailCount = $objMail->fnGetMailCount();
while($rows=$objMail->fnGetMail()){
print_r($rows->sTitle);
}

/*
// Test mysqli directly on page - same as fnGetMail()
$sql = "
SELECT *
FROM tblEmail
WHERE iToMemberID = ". $_SESSION["iMemberID"] ."
Order by dtEmailDate Desc";

$mysqli = new mysqli($aSiteSettings["sDBServer"],
$aSiteSettings["sDBLogin"],
$aSiteSettings["sDBPassword"],
$aSiteSettings["sDSN"]);
$query = $mysqli->query($sql);
while($rows = $query->fetch_object()){
print_r($rows->sTitle);
}
$mysqli->close;
*/
?>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация