-> PHP4 Singleton implementation question <-

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve JORDI

    -> PHP4 Singleton implementation question <-

    Hi,
    I'm trying to implement a singleton in PHP4 but it doesn't seem to
    work. The object is recreated each time I call it.

    The goal of the class is to keep a variable up to date.
    It's used to display a database content, 25 rows at a time.
    The singleton keeps track of the current starting row and
    increases it or decreases it by 25 depending on the user action
    (pressing a Next or Prev button).
    Those buttons are submit buttons calling the current form itself.

    But each time I re-enter that form, the singleton variable is created
    again and therefore the currentRow variable reinitilized.

    Thanks for any help?

    Here is the code for the class called Welcome:
    ---------------------------------------------
    class Welcome {
    var $offsetRows = 25;
    var $currentRow ;


    // *************** *************** *************** *************
    // INSTANCE function to instanciate this class only once
    // *************** *************** *************** *************
    function &getInstance () {
    static $instance ;
    if( !$instance ) {
    $instance = new Welcome() ;
    }
    return $instance ;
    }

    // *************** *************** *************** *************
    // CONSTRUCT function called when object is created
    // *************** *************** *************** *************
    function Welcome() {
    $this->currentRow = 0 ;
    $this->offsetRows = 25 ;
    }


    // *************** *************** *************** *************
    // SHOWRECORDS
    // Displays the actual table with info in rows.
    // *************** *************** *************** *************
    function showRecords() {
    // my table display code here using $this->currentRow
    }

    // *************** *************** *************** *************
    // NEXTRECORDS
    // Displays the next nn offset records
    // *************** *************** *************** *************
    function nextRecords() {
    $this->currentRow += $this->offsetRows ;
    $this->showRecords( ) ;
    }


    // *************** *************** *************** *************
    // PREVRECORDS
    // Displays the previous nn offset records if not at first
    // *************** *************** *************** *************
    function prevRecords() {
    $this->currentRow -= $this->offsetRows ;
    if( $this->currentRows < 0 )
    $this->currentRows = 0 ;
    $this->showRecords( ) ;
    }
    }


    Then my form works as follows:
    ------------------------------
    <FORM action="<?=$_SE RVER['PHP_SELF']?>" method="post">
    <?php
    require_once( "class_welcome. php" ) ;
    if( !$welcome ) {
    $welcome =& Welcome::getIns tance() ;
    }

    if(isset($_POST['next'])) {
    $welcome->nextRecords( ) ;
    }
    else {
    if(isset($_POST['previous'])) {
    $welcome->prevRecords( ) ;
    }
    else {
    $welcome->showRecords( ) ;
    }
    }
    ?>

    <P>
    <INPUT name="previous" type="submit" value="<<" />
    <INPUT name="next" type="submit" value=">>" />
    </FORM>




    Sincerely,
    Steve JORDI

    (Remove the K_I_L_LSPAM from my email address)
    ------------------------------------------------
    1197 Prangins Email: stevejordiK_I_L _LSPAM@hotmail. com
    Switzerland WWW: www.sjordi.com
    ------------------------------------------------
    Volcanoes at www.sjordi.com/volcanoes
    MovieDB at www.sjmoviedb.com
    ------------------------------------------------
  • Kimmo Laine

    #2
    Re: -&gt; PHP4 Singleton implementation question &lt;-

    "Steve JORDI" <steveK_I_L_LSP AMjordi@hotmail .comwrote in message
    news:o08tm2to3v t8bkkka03mqot1d bo2t83jhc@4ax.c om...
    Hi,
    I'm trying to implement a singleton in PHP4 but it doesn't seem to
    work. The object is recreated each time I call it.
    PHP4 is not the best platform for OOP. PHP5 has much more sophisticated
    object handling.
    The goal of the class is to keep a variable up to date.
    It's used to display a database content, 25 rows at a time.
    The singleton keeps track of the current starting row and
    increases it or decreases it by 25 depending on the user action
    (pressing a Next or Prev button).
    Those buttons are submit buttons calling the current form itself.
    >
    But each time I re-enter that form, the singleton variable is created
    again and therefore the currentRow variable reinitilize
    I'm guessing you have a C++ or Java background. The request/response
    architecture is quite different from a desktop application. A variable will
    not be available thru two different page calls unless it's stored as a
    session variable. Otherwise, each page call should be concidered as
    restarting an application and at the end of the page all variables are
    destroyed except for session variables.

    First I encourage you to go for php version 5, you'll get much more out of
    the classes and objects. Next thing you should do is learn how sessions
    work. And then finally, check out the singleton example at php.net:
    PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.


    --
    "Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
    http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
    spam@outolempi. net | rot13(xvzzb@bhg byrzcv.arg)


    Comment

    • Steve JORDI

      #3
      Re: -&gt; PHP4 Singleton implementation question &lt;-

      Kimmo,

      Thanks for your prompt reply,

      >PHP4 is not the best platform for OOP. PHP5 has much more sophisticated
      >object handling.
      Yes I know but for now I have no choice but to use the existing PHP 4
      in the company.
      >I'm guessing you have a C++
      Correct :-)

      >The request/response architecture is quite different from a desktop
      >application. A variable will not be available thru two different
      >page calls unless it's stored as a session variable.
      Mhhh... Interresting.
      >Otherwise, each page call should be concidered as restarting an
      >application and at the end of the page all variables are
      >destroyed except for session variables.
      OK.

      >First I encourage you to go for php version 5, you'll get much more out of
      >the classes and objects. Next thing you should do is learn how sessions
      >work.
      Ok I will check session matters. Thanks for the hint.
      >And then finally, check out the singleton example at php.net:
      >http://www.php.net/manual/en/language.oop5.patterns.php
      Yes, I've seen it, but it's for PHP 5 which I can't use right now.

      Thanks for your help.

      Sincerely,
      Steve JORDI

      (Remove the K_I_L_LSPAM from my email address)
      ------------------------------------------------
      1197 Prangins Email: stevejordiK_I_L _LSPAM@hotmail. com
      Switzerland WWW: www.sjordi.com
      ------------------------------------------------
      Volcanoes at www.sjordi.com/volcanoes
      MovieDB at www.sjmoviedb.com
      ------------------------------------------------

      Comment

      • Dikkie Dik

        #4
        Re: -&gt; PHP4 Singleton implementation question &lt;-

        <snip>
        Then my form works as follows:
        ------------------------------
        <FORM action="<?=$_SE RVER['PHP_SELF']?>" method="post">
        <?php
        require_once( "class_welcome. php" ) ;
        if( !$welcome ) {
        $welcome =& Welcome::getIns tance() ;
        }
        Following the PHP documentation on http://nl3.php.net/static , I would
        suggest to replace this last line with a non-referencing one:

        $welcome = Welcome::getIns tance() ;

        As was posted earlier, PHP5 has solved the objects-and-references problem.

        Best regards.

        Comment

        • Steve JORDI

          #5
          Re: -&gt; PHP4 Singleton implementation question &lt;-

          >Following the PHP documentation on http://nl3.php.net/static , I would
          >suggest to replace this last line with a non-referencing one:
          >$welcome = Welcome::getIns tance() ;
          Did this but it din't change a thing.
          >As was posted earlier, PHP5 has solved the objects-and-references problem.
          Yes, but I have to deal with PHP4, not 5 unfortunately.

          I also tried to set a $_SESSION['welcome'] variable, but still, each
          time I reenter my page, it's reassigned a new instance.

          It's crazy, I would never have thought that it would be such a hassle
          to keep a variable value between pages (without using URL parameters).

          Thanks anyway.

          Sincerely,
          Steve JORDI

          (Remove the K_I_L_LSPAM from my email address)
          ------------------------------------------------
          1197 Prangins Email: stevejordiK_I_L _LSPAM@hotmail. com
          Switzerland WWW: www.sjordi.com
          ------------------------------------------------
          Volcanoes at www.sjordi.com/volcanoes
          MovieDB at www.sjmoviedb.com
          ------------------------------------------------

          Comment

          • Dikkie Dik

            #6
            session (was: -&gt; PHP4 Singleton implementation question &lt;-)

            <snip>
            I also tried to set a $_SESSION['welcome'] variable, but still, each
            time I reenter my page, it's reassigned a new instance.
            >
            It's crazy, I would never have thought that it would be such a hassle
            to keep a variable value between pages (without using URL parameters).

            Sorry, I did not correctly read your message, and I thought it was
            re-created within one page request. If you want something kept between
            page requests, you'll need a session. There's no need to store the
            object itself in the session, although that is not impossible. Even
            then, the object will be re-created (unserialized) for each page visit.
            You can store just the data itself in the session (I assume it is one or
            more arrays) and have your instance check for existence of that session
            data at instantiation. Be sure to start the session before any data is
            sent to the client by calling session_start() . See
            http://nl3.php.net/manual/en/function.session-start.php for more info.

            Best regards.

            Comment

            • Jerry Stuckle

              #7
              Re: -&gt; PHP4 Singleton implementation question &lt;-

              Steve JORDI wrote:
              >>Following the PHP documentation on http://nl3.php.net/static , I would
              >>suggest to replace this last line with a non-referencing one:
              >>$welcome = Welcome::getIns tance() ;
              >
              >
              Did this but it din't change a thing.
              >
              >
              >>As was posted earlier, PHP5 has solved the objects-and-references problem.
              >
              >
              Yes, but I have to deal with PHP4, not 5 unfortunately.
              >
              I also tried to set a $_SESSION['welcome'] variable, but still, each
              time I reenter my page, it's reassigned a new instance.
              >
              It's crazy, I would never have thought that it would be such a hassle
              to keep a variable value between pages (without using URL parameters).
              >
              Thanks anyway.
              >
              Sincerely,
              Steve JORDI
              >
              (Remove the K_I_L_LSPAM from my email address)
              ------------------------------------------------
              1197 Prangins Email: stevejordiK_I_L _LSPAM@hotmail. com
              Switzerland WWW: www.sjordi.com
              ------------------------------------------------
              Volcanoes at www.sjordi.com/volcanoes
              MovieDB at www.sjmoviedb.com
              ------------------------------------------------
              Steve,

              If you've ever done any transactional processing, that's what web pages are.

              When the browser makes a request, the server starts a process (or
              thread) to handle the request. It allocates the necessary resources,
              and turns control over to your program (the php interpreter, in this
              case). The interpreter allocates additional resources as necessary to
              process your script and runs the script.

              When the script ends, the process reverses. The interpreter cleans up
              its resources and returns to the server. The server then cleans up the
              resources it allocated and terminates the process or thread.

              Each request is separate in itself. Resources are not kept, because
              another request may or may not follow this one. And if another request
              does come in, it may or may not be something you expect. And it may or
              may not be from the same user.

              Now, the developers understood there was a need to save information
              across requests. Therefore they implemented sessions to save the data
              on the server, and cookies to save it on the browser.

              So, if you want to save your object across the request, you need to
              store it in the session (not a good idea to store this in the cookie -
              too many people have cookies disabled, and saving them on the user's
              computer allows the user to edit the cookie).


              --
              =============== ===
              Remove the "x" from my email address
              Jerry Stuckle
              JDS Computer Training Corp.
              jstucklex@attgl obal.net
              =============== ===

              Comment

              • Steve JORDI

                #8
                Re: -&gt; PHP4 Singleton implementation question &lt;-

                Jerry,
                thanks for your explanations.

                I did actually try to save the variable as a session one, but
                it didn't seem to work.

                I had a
                start_session() ;

                Then, when entering or re-entering my page, it tests
                if( !isset($_SESSIO N['welcome']) )
                $_SESSION['welcome'] =& Welcome::GetIns tance() ;

                Problem is that it correctly get the instance the first time,
                but gets it again each time I re-enter my page.

                Shouldn't $_SESSION['welcome'] be saved within the session?

                From the literrature I read, it's the way to go, but clearly,
                something's wrong, I'm missing something.



                Sincerely,
                Steve JORDI

                (Remove the K_I_L_LSPAM from my email address)
                ------------------------------------------------
                1197 Prangins Email: stevejordiK_I_L _LSPAM@hotmail. com
                Switzerland WWW: www.sjordi.com
                ------------------------------------------------
                Volcanoes at www.sjordi.com/volcanoes
                MovieDB at www.sjmoviedb.com
                ------------------------------------------------

                Comment

                • Jerry Stuckle

                  #9
                  Re: -&gt; PHP4 Singleton implementation question &lt;-

                  Steve JORDI wrote:
                  Jerry,
                  thanks for your explanations.
                  >
                  I did actually try to save the variable as a session one, but
                  it didn't seem to work.
                  >
                  I had a
                  start_session() ;
                  >
                  Then, when entering or re-entering my page, it tests
                  if( !isset($_SESSIO N['welcome']) )
                  $_SESSION['welcome'] =& Welcome::GetIns tance() ;
                  >
                  Problem is that it correctly get the instance the first time,
                  but gets it again each time I re-enter my page.
                  >
                  Shouldn't $_SESSION['welcome'] be saved within the session?
                  >
                  From the literrature I read, it's the way to go, but clearly,
                  something's wrong, I'm missing something.
                  >
                  >
                  >
                  Sincerely,
                  Steve JORDI
                  >
                  (Remove the K_I_L_LSPAM from my email address)
                  ------------------------------------------------
                  1197 Prangins Email: stevejordiK_I_L _LSPAM@hotmail. com
                  Switzerland WWW: www.sjordi.com
                  ------------------------------------------------
                  Volcanoes at www.sjordi.com/volcanoes
                  MovieDB at www.sjmoviedb.com
                  ------------------------------------------------
                  Yes, and if your session is working, you it will be. Are you sure
                  NOTHING is sent to the browser before the session_start() call? No
                  white space, no DOCTYPE, nothing?

                  Enable all errors on the page by adding this at the top of your PHP code:

                  ini_set("displa y_errors","1");
                  error_reporting (E_ALL);

                  And see what you get.

                  --
                  =============== ===
                  Remove the "x" from my email address
                  Jerry Stuckle
                  JDS Computer Training Corp.
                  jstucklex@attgl obal.net
                  =============== ===

                  Comment

                  • Steve JORDI

                    #10
                    Re: -&gt; PHP4 Singleton implementation question &lt;-

                    OK I will check everything on Monday when back to work.
                    I'll keep you posted.
                    Thanks for your help anyway.

                    Sincerely,
                    Steve JORDI

                    (Remove the K_I_L_LSPAM from my email address)
                    ------------------------------------------------
                    1197 Prangins Email: stevejordiK_I_L _LSPAM@hotmail. com
                    Switzerland WWW: www.sjordi.com
                    ------------------------------------------------
                    Volcanoes at www.sjordi.com/volcanoes
                    MovieDB at www.sjmoviedb.com
                    ------------------------------------------------

                    Comment

                    • Tom

                      #11
                      Re: -&gt; PHP4 Singleton implementation question &lt;-

                      You probably have register_global s on and the session variable is
                      getting overwritten -- this problem drove me crazy for ages.

                      I finally figured it out recently and posted a comment on the php site
                      that will help if this is problem:



                      Good luck!

                      Tom


                      On Nov 30, 5:37 am, Steve JORDI <steveK_I_L_LSP AMjo...@hotmail .com>
                      wrote:
                      Following the PHP documentation onhttp://nl3.php.net/static, I would
                      suggest to replace this last line with a non-referencing one:
                      $welcome = Welcome::getIns tance() ;Did this but it din't change a thing.
                      >
                      As was posted earlier, PHP5 has solved the objects-and-references problem.Yes, but I have to deal with PHP4, not 5 unfortunately.
                      >
                      I also tried to set a $_SESSION['welcome'] variable, but still, each
                      time I reenter my page, it's reassigned a new instance.
                      >
                      It's crazy, I would never have thought that it would be such a hassle
                      to keep a variable value between pages (without using URL parameters).
                      >
                      Thanks anyway.
                      >
                      Sincerely,
                      Steve JORDI
                      >
                      (Remove the K_I_L_LSPAM from my email address)
                      ------------------------------------------------
                      1197 Prangins Email: stevejordiK_I_L _LS...@hotmail. com
                      Switzerland WWW: www.sjordi.com
                      ------------------------------------------------
                      Volcanoes at www.sjordi.com/volcanoes
                      MovieDB at www.sjmoviedb.com
                      ------------------------------------------------

                      Comment

                      • Steve JORDI

                        #12
                        Re: -&gt; PHP4 Singleton implementation question &lt;-

                        Jerry,
                        >Yes, and if your session is working, you it will be. Are you sure
                        >NOTHING is sent to the browser before the session_start() call? No
                        >white space, no DOCTYPE, nothing?
                        Yes, the start_session() call is the first line in the code.

                        >Enable all errors on the page by adding this at the top of your PHP code:
                        >ini_set("displ ay_errors","1") ;
                        >error_reportin g(E_ALL);
                        Yes, added this but didn't change anything. no message.
                        I'm using PHP4.4.4, is this the problem?


                        Sincerely,
                        Steve JORDI

                        (Remove the K_I_L_LSPAM from my email address)
                        ------------------------------------------------
                        1197 Prangins Email: stevejordiK_I_L _LSPAM@hotmail. com
                        Switzerland WWW: www.sjordi.com
                        ------------------------------------------------
                        Volcanoes at www.sjordi.com/volcanoes
                        MovieDB at www.sjmoviedb.com
                        ------------------------------------------------

                        Comment

                        • Jerry Stuckle

                          #13
                          Re: -&gt; PHP4 Singleton implementation question &lt;-

                          Steve JORDI wrote:
                          Jerry,
                          >
                          >
                          >>Yes, and if your session is working, you it will be. Are you sure
                          >>NOTHING is sent to the browser before the session_start() call? No
                          >>white space, no DOCTYPE, nothing?
                          >
                          >
                          Yes, the start_session() call is the first line in the code.
                          >
                          >
                          >
                          >>Enable all errors on the page by adding this at the top of your PHP code:
                          >>ini_set("disp lay_errors","1" );
                          >>error_reporti ng(E_ALL);
                          >
                          >
                          Yes, added this but didn't change anything. no message.
                          I'm using PHP4.4.4, is this the problem?
                          >
                          >
                          Sincerely,
                          Steve JORDI
                          >
                          (Remove the K_I_L_LSPAM from my email address)
                          ------------------------------------------------
                          1197 Prangins Email: stevejordiK_I_L _LSPAM@hotmail. com
                          Switzerland WWW: www.sjordi.com
                          ------------------------------------------------
                          Volcanoes at www.sjordi.com/volcanoes
                          MovieDB at www.sjmoviedb.com
                          ------------------------------------------------
                          No, PHP has supported sessions for a long time.

                          One thing - do you have the class definition included before the
                          session-start() call? I didn't think about this - but you have to have
                          the definition in there before you start the session. And does your
                          php.ini file automatically start sessions? If so, this could be the
                          problem, also.

                          --
                          =============== ===
                          Remove the "x" from my email address
                          Jerry Stuckle
                          JDS Computer Training Corp.
                          jstucklex@attgl obal.net
                          =============== ===

                          Comment

                          • Steve JORDI

                            #14
                            Re: -&gt; PHP4 Singleton implementation question &lt;-

                            Jerry,
                            I include the class definition before the start session
                            the PHP.INI is not set to start sessions automatically.

                            Maybe some code excerpts would help...


                            Here is the index.php start file:
                            --------------------------------
                            <?php
                            include_once( "class_welcome. php" ) ;
                            session_start() ;
                            ini_set("displa y_errors","1");
                            error_reporting (E_ALL);
                            header("Locatio n: ./passeportswelco me.php") ;
                            ?>



                            then I have passeportswelco me.php:
                            ----------------------------------
                            <body>
                            <FORM action="<?=$_SE RVER['PHP_SELF']?>" method="post">
                            <?php

                            if( !isset( $_SESSION['welcome'] ) )
                            $_SESSION['welcome'] =& Welcome::getIns tance() ;

                            if(isset($_POST['next'])) {
                            $_SESSION['welcome']->nextRecords( ) ;
                            }
                            else {
                            if(isset($_POST['previous'])) {
                            $_SESSION['welcome']->prevRecords( ) ;
                            }
                            else {
                            $_SESSION['welcome']->showRecords( ) ;
                            }
                            }

                            ?>

                            <P>
                            <INPUT name="previous" type="submit" value="&lt;&lt; " />
                            <INPUT name="next" type="submit" value="&gt;&gt; " />
                            </FORM>
                            </body>



                            and finally, here is the begining of the class_welcome.p hp:
                            -----------------------------------------------------------
                            <?php
                            // *************** *************** *************** *************
                            // CLASS WELCOME
                            // Displays records in a table
                            // Limited to nn records with nn chunks offsets
                            //
                            // This is a SINGLETON
                            // Use it in your main form as $obj = &Welcome::getIn stance() ;
                            // *************** *************** *************** *************
                            class Welcome {
                            var $offsetRows = 25;
                            var $currentRow ;


                            // *************** *************** *************** *************
                            // INSTANCE function to instanciate this class only once
                            // *************** *************** *************** *************
                            function &getInstance () {
                            static $instance ;
                            if( !$instance ) {
                            $instance = new Welcome() ;
                            }
                            return $instance ;
                            }

                            // *************** *************** *************** *************
                            // CONSTRUCTOR function called when object is created
                            // *************** *************** *************** *************
                            function Welcome() {
                            $this->currentRow = 0 ;
                            $this->offsetRows = 25 ;
                            }


                            // *************** *************** *************** *************
                            // SHOWRECORDS
                            // Displays the actual table with info in rows.
                            // *************** *************** *************** *************
                            function showRecords() {
                            // display code
                            }

                            // *************** *************** *************** *************
                            // NEXTRECORDS
                            // *************** *************** *************** *************
                            function nextRecords() {
                            $this->currentRow += $this->offsetRows ;
                            $this->showRecords( ) ;
                            }
                            }
                            ?>


                            What it does is correctly display my table from rows 0 to 25 going
                            through (I've added "echo" to each function)
                            ***WELCOME INSTANCE INIT***
                            ***WELCOME CONSTRUCTOR***
                            ***WELCOME INSTANCE ***
                            ***SHOW RECORDS***

                            Then if I click on the ">>" button (being "next" in the form), it
                            goes through
                            ***WELCOME INSTANCE INIT***
                            ***WELCOME CONSTRUCTOR***
                            ***WELCOME INSTANCE ***
                            ***NEXT RECORDS***
                            ***SHOW RECORDS***

                            As you can see, it instances Welceom again and goes again through
                            the constructor which initializes $currentRow to 0 again...
                            It should skip "Instance init" and "constructo r".

                            Thanks



                            Sincerely,
                            Steve JORDI

                            (Remove the K_I_L_LSPAM from my email address)
                            ------------------------------------------------
                            1197 Prangins Email: stevejordiK_I_L _LSPAM@hotmail. com
                            Switzerland WWW: www.sjordi.com
                            ------------------------------------------------
                            Volcanoes at www.sjordi.com/volcanoes
                            MovieDB at www.sjmoviedb.com
                            ------------------------------------------------

                            Comment

                            • Jerry Stuckle

                              #15
                              Re: -&gt; PHP4 Singleton implementation question &lt;-

                              Steve JORDI wrote:
                              Jerry,
                              I include the class definition before the start session
                              the PHP.INI is not set to start sessions automatically.
                              >
                              Maybe some code excerpts would help...
                              >
                              >
                              Here is the index.php start file:
                              --------------------------------
                              <?php
                              include_once( "class_welcome. php" ) ;
                              session_start() ;
                              ini_set("displa y_errors","1");
                              error_reporting (E_ALL);
                              header("Locatio n: ./passeportswelco me.php") ;
                              ?>
                              >
                              >
                              >
                              then I have passeportswelco me.php:
                              ----------------------------------
                              <body>
                              <FORM action="<?=$_SE RVER['PHP_SELF']?>" method="post">
                              <?php
                              >
                              if( !isset( $_SESSION['welcome'] ) )
                              $_SESSION['welcome'] =& Welcome::getIns tance() ;
                              >
                              if(isset($_POST['next'])) {
                              $_SESSION['welcome']->nextRecords( ) ;
                              }
                              else {
                              if(isset($_POST['previous'])) {
                              $_SESSION['welcome']->prevRecords( ) ;
                              }
                              else {
                              $_SESSION['welcome']->showRecords( ) ;
                              }
                              }
                              >
                              ?>
                              >
                              <P>
                              <INPUT name="previous" type="submit" value="&lt;&lt; " />
                              <INPUT name="next" type="submit" value="&gt;&gt; " />
                              </FORM>
                              </body>
                              >
                              >
                              >
                              and finally, here is the begining of the class_welcome.p hp:
                              -----------------------------------------------------------
                              <?php
                              // *************** *************** *************** *************
                              // CLASS WELCOME
                              // Displays records in a table
                              // Limited to nn records with nn chunks offsets
                              //
                              // This is a SINGLETON
                              // Use it in your main form as $obj = &Welcome::getIn stance() ;
                              // *************** *************** *************** *************
                              class Welcome {
                              var $offsetRows = 25;
                              var $currentRow ;
                              >
                              >
                              // *************** *************** *************** *************
                              // INSTANCE function to instanciate this class only once
                              // *************** *************** *************** *************
                              function &getInstance () {
                              static $instance ;
                              if( !$instance ) {
                              $instance = new Welcome() ;
                              }
                              return $instance ;
                              }
                              >
                              // *************** *************** *************** *************
                              // CONSTRUCTOR function called when object is created
                              // *************** *************** *************** *************
                              function Welcome() {
                              $this->currentRow = 0 ;
                              $this->offsetRows = 25 ;
                              }
                              >
                              >
                              // *************** *************** *************** *************
                              // SHOWRECORDS
                              // Displays the actual table with info in rows.
                              // *************** *************** *************** *************
                              function showRecords() {
                              // display code
                              }
                              >
                              // *************** *************** *************** *************
                              // NEXTRECORDS
                              // *************** *************** *************** *************
                              function nextRecords() {
                              $this->currentRow += $this->offsetRows ;
                              $this->showRecords( ) ;
                              }
                              }
                              ?>
                              >
                              >
                              What it does is correctly display my table from rows 0 to 25 going
                              through (I've added "echo" to each function)
                              ***WELCOME INSTANCE INIT***
                              ***WELCOME CONSTRUCTOR***
                              ***WELCOME INSTANCE ***
                              ***SHOW RECORDS***
                              >
                              Then if I click on the ">>" button (being "next" in the form), it
                              goes through
                              ***WELCOME INSTANCE INIT***
                              ***WELCOME CONSTRUCTOR***
                              ***WELCOME INSTANCE ***
                              ***NEXT RECORDS***
                              ***SHOW RECORDS***
                              >
                              As you can see, it instances Welceom again and goes again through
                              the constructor which initializes $currentRow to 0 again...
                              It should skip "Instance init" and "constructo r".
                              >
                              Thanks
                              >
                              >
                              >
                              Sincerely,
                              Steve JORDI
                              >
                              (Remove the K_I_L_LSPAM from my email address)
                              ------------------------------------------------
                              1197 Prangins Email: stevejordiK_I_L _LSPAM@hotmail. com
                              Switzerland WWW: www.sjordi.com
                              ------------------------------------------------
                              Volcanoes at www.sjordi.com/volcanoes
                              MovieDB at www.sjmoviedb.com
                              ------------------------------------------------
                              Ah, now I see the problem.

                              When you make the call

                              header("Locatio n: ./passeportswelco me.php") ;

                              you are telling the browser to load a new page. But on that page you
                              don't have a session-start() - or the include for your class.

                              Since it's a new page, everything starts over. You need the include and
                              session_start() call here, also.

                              --
                              =============== ===
                              Remove the "x" from my email address
                              Jerry Stuckle
                              JDS Computer Training Corp.
                              jstucklex@attgl obal.net
                              =============== ===

                              Comment

                              Working...