Problems with counter across pages

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

    #1

    Problems with counter across pages

    Hello,

    This is a simple thing but somehow I can't work it :((((

    I have a self-submitting form displaying data from a database. To keep
    track which data to show I want to create a variable that keeps track
    how many times the page is visited.

    The idea is:
    first call to page:var is not set => set var=0,
    subsequent calls:
    depending on the way the page was called* add or subract 1 from var
    (provided var is respectively < nrofrecords in database and < 0).

    *via a submit button called 'next page' or 'previous page'

    The code:
    // test 1
    echo"\$Submit = ".$Submit." - \$questionCount er =
    ".$questionCoun ter."<br>";

    if($questionCou nter==NULL)
    $questionCounte r=0;
    elseif($Submit= ="previous page")
    $questionCounte r=$questionCoun ter>0?$question Counter-1:$questionCoun ter;
    elseif($Submit= ="next page')
    $questionCounte r=($questionCou nter<getNumberO fQuestions($cat egory_id)-1)?$questionCou nter+1:$questio nCounter;

    //test 2
    echo"\$question Counter: ".$questionCoun ter."<br>";
    [color=blue]
    >getNumberOfQue stions($categor y_id) correctly returns amount of[/color]
    questions in db;[color=blue]
    >values for $Submit is set;
    >first call to $questionCounte r gives ""
    >second call to $questionCounte r gives 0
    >session.auto_s tart=1 in php.ini[/color]

    $questionCounte r never adds up. Always when I call the page via the
    'next page' button the initial value of $questionCounte r ="", after
    the code it's 0

    What's wrong - how can I make this work?

    Thanks,

    Marc
  • Tom Thackrey

    #2
    Re: Problems with counter across pages


    On 13-Oct-2003, meelzooi2000@ya hoo.com (Marc) wrote:
    [color=blue]
    > I have a self-submitting form displaying data from a database. To keep
    > track which data to show I want to create a variable that keeps track
    > how many times the page is visited.
    >
    > The idea is:
    > first call to page:var is not set => set var=0,
    > subsequent calls:
    > depending on the way the page was called* add or subract 1 from var
    > (provided var is respectively < nrofrecords in database and < 0).
    >
    > *via a submit button called 'next page' or 'previous page'
    >
    > The code:
    > // test 1
    > echo"\$Submit = ".$Submit." - \$questionCount er =
    > ".$questionCoun ter."<br>";
    >
    > if($questionCou nter==NULL)
    > $questionCounte r=0;
    > elseif($Submit= ="previous page")
    > $questionCounte r=$questionCoun ter>0?$question Counter-1:$questionCoun ter;
    > elseif($Submit= ="next page')
    > $questionCounte r=($questionCou nter<getNumberO fQuestions($cat egory_id)-1)?$questionCou nter+1:$questio nCounter;
    >
    > //test 2
    > echo"\$question Counter: ".$questionCoun ter."<br>";
    >[color=green]
    > >getNumberOfQue stions($categor y_id) correctly returns amount of[/color]
    > questions in db;[color=green]
    > >values for $Submit is set;
    > >first call to $questionCounte r gives ""
    > >second call to $questionCounte r gives 0
    > >session.auto_s tart=1 in php.ini[/color]
    >
    > $questionCounte r never adds up. Always when I call the page via the
    > 'next page' button the initial value of $questionCounte r ="", after
    > the code it's 0
    >
    > What's wrong - how can I make this work?[/color]

    The value of the counter is NOT automatically preserved between pages.
    You either need to stash the value of the counter in a hidden input field
    (<input type="hidden" ...) on the page or use sessions and a $_SESSION
    variable.



    --
    Tom Thackrey

    tom (at) creative (dash) light (dot) com
    do NOT send email to jamesbutler@wil lglen.net (it's reserved for spammers)

    Comment

    Working...