For some reason, I am having trouble retrieving the data that I store
in the object that I have created from a database query. I created
this class Lead (see below). In the php page, I create and array of
Lead objects and later on down the page I iterate through the array of
leads, retrieving each Lead and calling the get methods. However the
get methods are not returning any values. I think I've copied the
important parts of the code below, does anything standout around why my
$lead->getFirstName () is returning ""? Thanks in advance.
class Lead:
-------------------------------------------------
class Lead {
var $username;
var $password;
var $firstName;
var $lastName;
var $email;
var $phone;
var $leadID;
var $lastLogin;
var $dateCreated;
var $confirmed;
function Leads($firstNam e, $lastName, $email, $phone, $leadID) {
$this->firstName = $firstName;
$this->lastName = $lastName;
$this->email = $email;
$this->phone = $phone;
$this->leadID = $leadID;
}
function setUsername($us ername) {$this->username = $username;}
function setPassword($pa ssword) {$this->password = $password;}
function setLastLogin($l astLogin) {$this->lastLogin = $lastLogin;}
function setDateCreated( $dateCreated) {
$this->dateCreated = $dateCreated;
}
function setConfirmed($c onfirmed) {$this->confirmed = $confirmed;}
function getFirstName() {return $this->firstName;}
function getLastName() {return $this->lastName;}
function getEmail() {return $this->email;}
function getPhone() {return $this->phone;}
function getLeadID() {return $this->leadID;}
}
-------------------------------------------------------
php page:
----------------------------------------------------------------------
// $res is the result of a previous query that isn't important in this
problem
$leads = array();
$nrows = mysql_num_rows( $res);
for($i = 0; $i < $nrows; $i++) {
$row = mysql_fetch_ass oc($res);
$leadID = $row["Lead_ID"];
$res2 = mysql_query("SE LECT * from LEADS where Lead_ID = $leadID",
$hd) or die("Unable to run query: " . mysql_error());
$row2 = mysql_fetch_ass oc($res2);
$firstName = $row2["FirstName"];
$lastName = $row2["LastName"];
$phone = $row2["Phone"];
$email = $row2["Email"];
$leads[$i] = new Lead($firstName , $lastName, $email,
$phone, $leadID);
}
?>
HTML stuff here
<?php
for($i = 0; $i < count($leads); $i++) {
print $i;
$lead = $leads[$i];
?>
<tr>
<td class="tabdata" ><?php echo($i+1)?>.</td>
<td class="tabdata" ><?php echo($lead->getFirstName() )?></td>
<td class="tabdata" ><?php echo($lead->getLastName()) ?></td>
<td class="tabdata" ><?php echo($lead->getPhone())? ></td>
<td class="tabdata" ><?php echo($lead->getEmail())? ></td>
</tr>
<?php
}
?>
-----------------------------------------
in the object that I have created from a database query. I created
this class Lead (see below). In the php page, I create and array of
Lead objects and later on down the page I iterate through the array of
leads, retrieving each Lead and calling the get methods. However the
get methods are not returning any values. I think I've copied the
important parts of the code below, does anything standout around why my
$lead->getFirstName () is returning ""? Thanks in advance.
class Lead:
-------------------------------------------------
class Lead {
var $username;
var $password;
var $firstName;
var $lastName;
var $email;
var $phone;
var $leadID;
var $lastLogin;
var $dateCreated;
var $confirmed;
function Leads($firstNam e, $lastName, $email, $phone, $leadID) {
$this->firstName = $firstName;
$this->lastName = $lastName;
$this->email = $email;
$this->phone = $phone;
$this->leadID = $leadID;
}
function setUsername($us ername) {$this->username = $username;}
function setPassword($pa ssword) {$this->password = $password;}
function setLastLogin($l astLogin) {$this->lastLogin = $lastLogin;}
function setDateCreated( $dateCreated) {
$this->dateCreated = $dateCreated;
}
function setConfirmed($c onfirmed) {$this->confirmed = $confirmed;}
function getFirstName() {return $this->firstName;}
function getLastName() {return $this->lastName;}
function getEmail() {return $this->email;}
function getPhone() {return $this->phone;}
function getLeadID() {return $this->leadID;}
}
-------------------------------------------------------
php page:
----------------------------------------------------------------------
// $res is the result of a previous query that isn't important in this
problem
$leads = array();
$nrows = mysql_num_rows( $res);
for($i = 0; $i < $nrows; $i++) {
$row = mysql_fetch_ass oc($res);
$leadID = $row["Lead_ID"];
$res2 = mysql_query("SE LECT * from LEADS where Lead_ID = $leadID",
$hd) or die("Unable to run query: " . mysql_error());
$row2 = mysql_fetch_ass oc($res2);
$firstName = $row2["FirstName"];
$lastName = $row2["LastName"];
$phone = $row2["Phone"];
$email = $row2["Email"];
$leads[$i] = new Lead($firstName , $lastName, $email,
$phone, $leadID);
}
?>
HTML stuff here
<?php
for($i = 0; $i < count($leads); $i++) {
print $i;
$lead = $leads[$i];
?>
<tr>
<td class="tabdata" ><?php echo($i+1)?>.</td>
<td class="tabdata" ><?php echo($lead->getFirstName() )?></td>
<td class="tabdata" ><?php echo($lead->getLastName()) ?></td>
<td class="tabdata" ><?php echo($lead->getPhone())? ></td>
<td class="tabdata" ><?php echo($lead->getEmail())? ></td>
</tr>
<?php
}
?>
-----------------------------------------
Comment