getter/setter methods not working

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Greg Scharlemann

    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($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
    }
    ?>
    -----------------------------------------

  • Janwillem Borleffs

    #2
    Re: getter/setter methods not working

    Greg Scharlemann wrote:[color=blue]
    > 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 {[/color]
    [...][color=blue]
    > function Leads($firstNam e, $lastName, $email, $phone, $leadID) {
    > $this->firstName = $firstName;
    > $this->lastName = $lastName;
    > $this->email = $email;
    > $this->phone = $phone;
    > $this->leadID = $leadID;
    > }
    >[/color]

    Incorrect constructor name; it should be Lead instead of Leads.


    JW


    Comment

    • Iván Sánchez Ortega

      #3
      Re: getter/setter methods not working

      -----BEGIN PGP SIGNED MESSAGE-----
      Hash: SHA1

      Janwillem Borleffs wrote:
      [color=blue]
      > Incorrect constructor name; it should be Lead instead of Leads.[/color]

      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-----

      Comment

      • Jim Michaels

        #4
        Re: getter/setter methods not working


        "Iván Sánchez Ortega" <i.punto.sanche z--@rroba--mirame.punto.ne t> wrote in
        message news:1h20b3-kej.ln1@blacksp ark.escomposlin ux.org...[color=blue]
        > -----BEGIN PGP SIGNED MESSAGE-----
        > Hash: SHA1
        >
        > Janwillem Borleffs wrote:
        >[color=green]
        >> Incorrect constructor name; it should be Lead instead of Leads.[/color]
        >
        > 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.
        >[/color]

        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

        [color=blue]
        > - --
        > - ----------------------------------
        > 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-----[/color]


        Comment

        • Jim Michaels

          #5
          Re: getter/setter methods not working


          "Jim Michaels" <jmichae3@nospa m.yahoo.com> wrote in message
          news:JemdnRRZVd JrO3benZ2dnUVZ_ tKdnZ2d@comcast .com...[color=blue]
          >
          > "Iván Sánchez Ortega" <i.punto.sanche z--@rroba--mirame.punto.ne t> wrote in
          > message news:1h20b3-kej.ln1@blacksp ark.escomposlin ux.org...[color=green]
          >> -----BEGIN PGP SIGNED MESSAGE-----
          >> Hash: SHA1
          >>
          >> Janwillem Borleffs wrote:
          >>[color=darkred]
          >>> Incorrect constructor name; it should be Lead instead of Leads.[/color]
          >>
          >> 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.
          >>[/color]
          >
          > I don't remember seeing that in the manual for a constructor, so how is it
          > supported? I see[/color]

          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

          [color=blue]
          >
          >[color=green]
          >> - --
          >> - ----------------------------------
          >> 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-----[/color]
          >
          >[/color]


          Comment

          • Iván Sánchez Ortega

            #6
            Re: getter/setter methods not working

            Jim Michaels wrote:
            [color=blue][color=green]
            >> Note: In PHP5, it is preferred to name the constructor "__construc t"[/color][/color]
            [...][color=blue]
            > I don't remember seeing that in the manual for a constructor, so how is it
            > supported?[/color]

            It *is* in the manual.




            --
            ----------------------------------
            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

            Comment

            Working...