473,383 Members | 1,870 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

getter/setter methods not working

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($firstName, $lastName, $email, $phone, $leadID) {
$this->firstName = $firstName;
$this->lastName = $lastName;
$this->email = $email;
$this->phone = $phone;
$this->leadID = $leadID;
}
function setUsername($username) {$this->username = $username;}
function setPassword($password) {$this->password = $password;}
function setLastLogin($lastLogin) {$this->lastLogin = $lastLogin;}
function setDateCreated($dateCreated) {
$this->dateCreated = $dateCreated;
}
function setConfirmed($confirmed) {$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_assoc($res);
$leadID = $row["Lead_ID"];

$res2 = mysql_query("SELECT * from LEADS where Lead_ID = $leadID",
$hd) or die("Unable to run query: " . mysql_error());
$row2 = mysql_fetch_assoc($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
}
?>
-----------------------------------------

Jan 29 '06 #1
5 2371
Greg Scharlemann wrote:
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 { [...] function Leads($firstName, $lastName, $email, $phone, $leadID) {
$this->firstName = $firstName;
$this->lastName = $lastName;
$this->email = $email;
$this->phone = $phone;
$this->leadID = $leadID;
}


Incorrect constructor name; it should be Lead instead of Leads.
JW
Jan 29 '06 #2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Janwillem Borleffs wrote:
Incorrect constructor name; it should be Lead instead of Leads.


Note: In PHP5, it is preferred to name the constructor "__construct" instead
of naming it as the class name. That just avoids things like this, you
know.

- --
- ----------------------------------
Iván Sánchez Ortega -i-punto-sanchez--arroba-mirame-punto-net

Why one contradicts. One often contradicts an opinion when it is really only
the way in which it has been presented that is unsympathetic.
-- Friedrich Nietzsche [1844 - 1900]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFD3Vq23jcQ2mg3Pc8RAnBIAJ9rO31gH1aAQcVWRi5S9l wDj0zdMgCgh4YA
lsTg11aE545tDFFXlewzApA=
=SP+g
-----END PGP SIGNATURE-----
Jan 30 '06 #3

"Iván Sánchez Ortega" <i.***************@rroba--mirame.punto.net> wrote in
message news:1h************@blackspark.escomposlinux.org.. .
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Janwillem Borleffs wrote:
Incorrect constructor name; it should be Lead instead of Leads.
Note: In PHP5, it is preferred to name the constructor "__construct"
instead
of naming it as the class name. That just avoids things like this, you
know.


I don't remember seeing that in the manual for a constructor, so how is it
supported? I see
class Vegetable {

var $edible;
var $color;

function Vegetable($edible, $color="green")
{
$this->edible = $edible;
$this->color = $color;
}

function is_edible()
{
return $this->edible;
}

function what_color()
{
return $this->color;
}

} // end of class Vegetable

- --
- ----------------------------------
Iván Sánchez Ortega -i-punto-sanchez--arroba-mirame-punto-net

Why one contradicts. One often contradicts an opinion when it is really
only
the way in which it has been presented that is unsympathetic.
-- Friedrich Nietzsche [1844 - 1900]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFD3Vq23jcQ2mg3Pc8RAnBIAJ9rO31gH1aAQcVWRi5S9l wDj0zdMgCgh4YA
lsTg11aE545tDFFXlewzApA=
=SP+g
-----END PGP SIGNATURE-----

Feb 9 '06 #4

"Jim Michaels" <jm******@nospam.yahoo.com> wrote in message
news:Je******************************@comcast.com. ..

"Iván Sánchez Ortega" <i.***************@rroba--mirame.punto.net> wrote in
message news:1h************@blackspark.escomposlinux.org.. .
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Janwillem Borleffs wrote:
Incorrect constructor name; it should be Lead instead of Leads.
Note: In PHP5, it is preferred to name the constructor "__construct"
instead
of naming it as the class name. That just avoids things like this, you
know.


I don't remember seeing that in the manual for a constructor, so how is it
supported? I see


Never mind. I found this in the user notes. Why isn't stuff like this in
the manuals instead of just the user notes?
<?php
class A { var $value = "Class A\n"; }
class B { var $value = "Class B\n"; }
// Uncomment which extender you want. You can use variables as well.
// define('__EXTENDER__', 'A');
define('__EXTENDER__', 'B');
// Use eval to create a wrapper class.
eval('class EXTENDER extends '. __EXTENDER__ . ' { }');
class C extends EXTENDER
{
function __construct()
{
echo $this->value;
}
}
$t = new C;
?>
Outputs: Class B


- --
- ----------------------------------
Iván Sánchez Ortega -i-punto-sanchez--arroba-mirame-punto-net

Why one contradicts. One often contradicts an opinion when it is really
only
the way in which it has been presented that is unsympathetic.
-- Friedrich Nietzsche [1844 - 1900]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFD3Vq23jcQ2mg3Pc8RAnBIAJ9rO31gH1aAQcVWRi5S9l wDj0zdMgCgh4YA
lsTg11aE545tDFFXlewzApA=
=SP+g
-----END PGP SIGNATURE-----


Feb 9 '06 #5
Jim Michaels wrote:
Note: In PHP5, it is preferred to name the constructor "__construct"
[...] I don't remember seeing that in the manual for a constructor, so how is it
supported?


It *is* in the manual.

http://www.php.net/manual/en/language.oop5.decon.php
--
----------------------------------
Iván Sánchez Ortega -i-punto-sanchez--arroba-mirame-punto-net

"No es extrańo: Internet es un peligro para cualquier dictadura"
--Carlos Sánchez Almeida
Feb 9 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Kiwi | last post by:
Hello. I know a getter can return other thing than a field. I know a setter can do more things than setting a field. I know there are "setter only" cases and "getter only" cases. I do use...
8
by: Herve Bocuse | last post by:
Hi, I'm just wondering what are the guidelines for using a Property or a pair of get/set methods related to a member variable ? What do yu guys do ? Thank you Herve
1
by: Steve | last post by:
I generate C# webservices proxy code from WSDL file, it turns out the classes generated have public member variables and no getter/setter methods as follows, and I am able to get data when...
12
by: Adam Sandler | last post by:
Hi all, I hope this is an easy one... Using VWD 2005. When I call my accessor method (getName) I always receive an empty string back. Debugging shows there should be something there but I...
5
by: kronrn | last post by:
Hi Folks Can anyone confirm that the code public string Name { get; set; }
3
by: Martin Pöpping | last post by:
Hello, I´m coming from the Java World. Here Programmers often use (like in C++?) getter and setter methods. F.e.: class Mirror{ private int width_;
26
by: Cliff Williams | last post by:
Can someone explain the pros/cons of these different ways of creating a class? // 1 function myclass() { this.foo1 = function() {...} } // 2a
3
by: nelsonbrodyk | last post by:
Hey all, Just curious, I want to make the "set" in a property obsolete, but not the get or the property. Is there a way to do this? Public string FirstName { get; set; } works fine, but...
9
by: jeddiki | last post by:
Hi, I have just started learning OOP and have a couple of questions. Is it correct to say that if I write a constructor method for my class then I will not need to use he set method to add...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.