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
}
?>
----------------------------------------- 5 2421
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($firstNam e, $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
-----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 "__construc t" 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)
iD8DBQFD3Vq23jc Q2mg3Pc8RAnBIAJ 9rO31gH1aAQcVWR i5S9lwDj0zdMgCg h4YA
lsTg11aE545tDFF XlewzApA=
=SP+g
-----END PGP SIGNATURE-----
"Iván Sánchez Ortega" <i.************ ***@rroba--mirame.punto.ne t> 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 "__construc t" 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($edib le, $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)
iD8DBQFD3Vq23jc Q2mg3Pc8RAnBIAJ 9rO31gH1aAQcVWR i5S9lwDj0zdMgCg h4YA lsTg11aE545tDFF XlewzApA= =SP+g -----END PGP SIGNATURE-----
"Jim Michaels" <jm******@nospa m.yahoo.com> wrote in message
news:Je******** *************** *******@comcast .com... "Iván Sánchez Ortega" <i.************ ***@rroba--mirame.punto.ne t> 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 "__construc t" 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('__EXTEN DER__', 'A');
define('__EXTEN DER__', '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)
iD8DBQFD3Vq23jc Q2mg3Pc8RAnBIAJ 9rO31gH1aAQcVWR i5S9lwDj0zdMgCg h4YA lsTg11aE545tDFF XlewzApA= =SP+g -----END PGP SIGNATURE-----
Jim Michaels wrote: Note: In PHP5, it is preferred to name the constructor "__construc t"
[...] 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 getters and setters when needed.
But most of getter/setter pairs I have seen are just like below;
> private int x;
> public int getX() { return x; }
> public void setX(int x) { this.x = x; }
|
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
|
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 running the client.
public class MyFeeResponse {
|
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 cannot figure out where the
problem is actually occurring.
The first couple of lines of my code behind:
Partial Class _Default
|
by: kronrn |
last post by:
Hi Folks
Can anyone confirm that the code
public string Name
{
get;
set;
}
| |
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_;
|
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
|
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 this fails:
|
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 values to properties ?
i.e. with this:
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |