I'm creating a pseudo-mail 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.

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;
*/
?>




Community email addresses:
  Post message: [email protected]
  Subscribe:    [EMAIL PROTECTED]
  Unsubscribe:  [EMAIL PROTECTED]
  List owner:   [EMAIL PROTECTED]

Shortcut URL to this page:
  http://groups.yahoo.com/group/php-list 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php-list/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to