On 13-Oct-2003,
meelzooi2000@yahoo.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." - \$questionCounter =
> ".$questionCounter."<br>";
>
> if($questionCounter==NULL)
> $questionCounter=0;
> elseif($Submit=="previous page")
> $questionCounter=$questionCounter>0?$questionCount er-1:$questionCounter;
> elseif($Submit=="next page')
> $questionCounter=($questionCounter<getNumberOfQues tions($category_id)-1)?$questionCounter+1:$questionCounter;
>
> //test 2
> echo"\$questionCounter: ".$questionCounter."<br>";
>[color=green]
> >getNumberOfQuestions($category_id) correctly returns amount of[/color]
> questions in db;[color=green]
> >values for $Submit is set;
> >first call to $questionCounter gives ""
> >second call to $questionCounter gives 0
> >session.auto_start=1 in php.ini[/color]
>
> $questionCounter never adds up. Always when I call the page via the
> 'next page' button the initial value of $questionCounter ="", 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.
http://www.php.net/manual/en/ref.session.php
--
Tom Thackrey
www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to
jamesbutler@willglen.net (it's reserved for spammers)