Help with session count code
Help with session count code
am 03.11.2007 00:19:13 von Chris
I am trying to increase/decrease the value of $_SESSION['count'] by 1
after clicking on a link e.g index.php?gotoWk=nxtWk and index.php?
gotoWk=lstWk. I'm sure you will get the drift if you look at the code
below.
However, this code seems to be unreliable. Is there a more robust way
of achieving the same thing?
Many thanks,
Chris
if (!isset($_SESSION['count'])) {
$_SESSION['count'] = 0;
} elseif($_REQUEST['gotoWk'] == "nxtWk") {
$_SESSION['count']++;
} elseif($_REQUEST['gotoWk'] == "lstWk") {
$_SESSION['count']--;
}
Re: Help with session count code
am 03.11.2007 00:51:01 von zeldorblat
On Nov 2, 7:19 pm, Chris wrote:
> I am trying to increase/decrease the value of $_SESSION['count'] by 1
> after clicking on a link e.g index.php?gotoWk=nxtWk and index.php?
> gotoWk=lstWk. I'm sure you will get the drift if you look at the code
> below.
>
> However, this code seems to be unreliable. Is there a more robust way
> of achieving the same thing?
>
What do you mean by "seems to be unreliable?"
Re: Help with session count code
am 03.11.2007 07:12:21 von Chris Gorospe
Chris wrote:
> I am trying to increase/decrease the value of $_SESSION['count'] by 1
> after clicking on a link e.g index.php?gotoWk=nxtWk and index.php?
> gotoWk=lstWk. I'm sure you will get the drift if you look at the code
> below.
>
> However, this code seems to be unreliable. Is there a more robust way
> of achieving the same thing?
>
> Many thanks,
>
> Chris
>
> if (!isset($_SESSION['count'])) {
> $_SESSION['count'] = 0;
> } elseif($_REQUEST['gotoWk'] == "nxtWk") {
> $_SESSION['count']++;
> } elseif($_REQUEST['gotoWk'] == "lstWk") {
> $_SESSION['count']--;
> }
>
I don't see what why you think it's unreliable. Looks like it should do
exactly what you're explaining you want done. The only thing i'd
personally change is the $_REQUEST. I would use $_GET instead.
Re: Help with session count code
am 03.11.2007 09:59:37 von Chris
On 3 Nov, 06:12, Chris Gorospe wrote:
> Chris wrote:
> > I am trying to increase/decrease the value of $_SESSION['count'] by 1
> > after clicking on a link e.g index.php?gotoWk=nxtWk and index.php?
> > gotoWk=lstWk. I'm sure you will get the drift if you look at the code
> > below.
>
> > However, this code seems to be unreliable. Is there a more robust way
> > of achieving the same thing?
>
> > Many thanks,
>
> > Chris
>
> > if (!isset($_SESSION['count'])) {
> > $_SESSION['count'] = 0;
> > } elseif($_REQUEST['gotoWk'] == "nxtWk") {
> > $_SESSION['count']++;
> > } elseif($_REQUEST['gotoWk'] == "lstWk") {
> > $_SESSION['count']--;
> > }
>
> I don't see what why you think it's unreliable. Looks like it should do
> exactly what you're explaining you want done. The only thing i'd
> personally change is the $_REQUEST. I would use $_GET instead.- Hide quoted text -
>
> - Show quoted text -
It is not reliable in that when a link is clicked it doesn't always
add or take away 1 appropiately?
Cheers,
Chris
Re: Help with session count code
am 03.11.2007 10:17:11 von Chris
On 3 Nov, 06:12, Chris Gorospe wrote:
> Chris wrote:
> > I am trying to increase/decrease the value of $_SESSION['count'] by 1
> > after clicking on a link e.g index.php?gotoWk=nxtWk and index.php?
> > gotoWk=lstWk. I'm sure you will get the drift if you look at the code
> > below.
>
> > However, this code seems to be unreliable. Is there a more robust way
> > of achieving the same thing?
>
> > Many thanks,
>
> > Chris
>
> > if (!isset($_SESSION['count'])) {
> > $_SESSION['count'] = 0;
> > } elseif($_REQUEST['gotoWk'] == "nxtWk") {
> > $_SESSION['count']++;
> > } elseif($_REQUEST['gotoWk'] == "lstWk") {
> > $_SESSION['count']--;
> > }
>
> I don't see what why you think it's unreliable. Looks like it should do
> exactly what you're explaining you want done. The only thing i'd
> personally change is the $_REQUEST. I would use $_GET instead.- Hide quoted text -
>
> - Show quoted text -
Just to clarify why I need help.
If I use the code above when I click my add '>>' link first time all
is ok. The next take away click '<<' adds 1 then starts taking away 1
with further clicks. Returning to '>>' takes away 1 and then continues
to add 1?
Very confused?!
Cheers,
Chris
Re: Help with session count code
am 03.11.2007 14:44:57 von Jerry Stuckle
Chris wrote:
> On 3 Nov, 06:12, Chris Gorospe wrote:
>> Chris wrote:
>>> I am trying to increase/decrease the value of $_SESSION['count'] by 1
>>> after clicking on a link e.g index.php?gotoWk=nxtWk and index.php?
>>> gotoWk=lstWk. I'm sure you will get the drift if you look at the code
>>> below.
>>> However, this code seems to be unreliable. Is there a more robust way
>>> of achieving the same thing?
>>> Many thanks,
>>> Chris
>>> if (!isset($_SESSION['count'])) {
>>> $_SESSION['count'] = 0;
>>> } elseif($_REQUEST['gotoWk'] == "nxtWk") {
>>> $_SESSION['count']++;
>>> } elseif($_REQUEST['gotoWk'] == "lstWk") {
>>> $_SESSION['count']--;
>>> }
>> I don't see what why you think it's unreliable. Looks like it should do
>> exactly what you're explaining you want done. The only thing i'd
>> personally change is the $_REQUEST. I would use $_GET instead.- Hide quoted text -
>>
>> - Show quoted text -
>
> Just to clarify why I need help.
>
> If I use the code above when I click my add '>>' link first time all
> is ok. The next take away click '<<' adds 1 then starts taking away 1
> with further clicks. Returning to '>>' takes away 1 and then continues
> to add 1?
>
> Very confused?!
>
> Cheers,
>
> Chris
>
>
Then you aren't telling us the entire story, Chris. This code won't
work that way.
Let's see ALL the code you're using.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Re: Help with session count code
am 03.11.2007 16:14:26 von Chris
On 3 Nov, 13:44, Jerry Stuckle wrote:
> Chris wrote:
> > On 3 Nov, 06:12, Chris Gorospe wrote:
> >> Chris wrote:
> >>> I am trying to increase/decrease the value of $_SESSION['count'] by 1
> >>> after clicking on a link e.g index.php?gotoWk=nxtWk and index.php?
> >>> gotoWk=lstWk. I'm sure you will get the drift if you look at the code
> >>> below.
> >>> However, this code seems to be unreliable. Is there a more robust way
> >>> of achieving the same thing?
> >>> Many thanks,
> >>> Chris
> >>> if (!isset($_SESSION['count'])) {
> >>> $_SESSION['count'] = 0;
> >>> } elseif($_REQUEST['gotoWk'] == "nxtWk") {
> >>> $_SESSION['count']++;
> >>> } elseif($_REQUEST['gotoWk'] == "lstWk") {
> >>> $_SESSION['count']--;
> >>> }
> >> I don't see what why you think it's unreliable. Looks like it should do
> >> exactly what you're explaining you want done. The only thing i'd
> >> personally change is the $_REQUEST. I would use $_GET instead.- Hide quoted text -
>
> >> - Show quoted text -
>
> > Just to clarify why I need help.
>
> > If I use the code above when I click my add '>>' link first time all
> > is ok. The next take away click '<<' adds 1 then starts taking away 1
> > with further clicks. Returning to '>>' takes away 1 and then continues
> > to add 1?
>
> > Very confused?!
>
> > Cheers,
>
> > Chris
>
> Then you aren't telling us the entire story, Chris. This code won't
> work that way.
>
> Let's see ALL the code you're using.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================- Hide quoted text -
>
> - Show quoted text -
Jerry,
All code attached.
Cheers,
Chris
// Count for weekno
if (!isset($_SESSION['count'])) {
$_SESSION['count'] = 0;
}
if($_GET['nxtWk'] == '1') {
$_SESSION['count']++;
}
if($_GET['lstWk'] == '1') {
$_SESSION['count']--;
}
$_SESSION['weeknumber'] = date('W')+$_SESSION['count'];
--html--
Back Next
href="index.php?nxtWk=1">>>
=$_SESSION['weeknumber']; ?>
Re: Help with session count code
am 03.11.2007 17:53:04 von Jerry Stuckle
Chris wrote:
> On 3 Nov, 13:44, Jerry Stuckle wrote:
>> Chris wrote:
>>> On 3 Nov, 06:12, Chris Gorospe wrote:
>>>> Chris wrote:
>>>>> I am trying to increase/decrease the value of $_SESSION['count'] by 1
>>>>> after clicking on a link e.g index.php?gotoWk=nxtWk and index.php?
>>>>> gotoWk=lstWk. I'm sure you will get the drift if you look at the code
>>>>> below.
>>>>> However, this code seems to be unreliable. Is there a more robust way
>>>>> of achieving the same thing?
>>>>> Many thanks,
>>>>> Chris
>>>>> if (!isset($_SESSION['count'])) {
>>>>> $_SESSION['count'] = 0;
>>>>> } elseif($_REQUEST['gotoWk'] == "nxtWk") {
>>>>> $_SESSION['count']++;
>>>>> } elseif($_REQUEST['gotoWk'] == "lstWk") {
>>>>> $_SESSION['count']--;
>>>>> }
>>>> I don't see what why you think it's unreliable. Looks like it should do
>>>> exactly what you're explaining you want done. The only thing i'd
>>>> personally change is the $_REQUEST. I would use $_GET instead.- Hide quoted text -
>>>> - Show quoted text -
>>> Just to clarify why I need help.
>>> If I use the code above when I click my add '>>' link first time all
>>> is ok. The next take away click '<<' adds 1 then starts taking away 1
>>> with further clicks. Returning to '>>' takes away 1 and then continues
>>> to add 1?
>>> Very confused?!
>>> Cheers,
>>> Chris
>> Then you aren't telling us the entire story, Chris. This code won't
>> work that way.
>>
>> Let's see ALL the code you're using.
>>
>> --
>> ==================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> JDS Computer Training Corp.
>> jstuck...@attglobal.net
>> ==================- Hide quoted text -
>>
>> - Show quoted text -
>
> Jerry,
>
> All code attached.
>
> Cheers,
>
> Chris
>
> // Count for weekno
> if (!isset($_SESSION['count'])) {
> $_SESSION['count'] = 0;
> }
> if($_GET['nxtWk'] == '1') {
> $_SESSION['count']++;
> }
> if($_GET['lstWk'] == '1') {
> $_SESSION['count']--;
> }
>
> $_SESSION['weeknumber'] = date('W')+$_SESSION['count'];
>
> --html--
> Back Next
> href="index.php?nxtWk=1">>>
> =$_SESSION['weeknumber']; ?>
>
>
>
Why are you adding or subtracting the count from the current week number?
And why are you even storing the count in $_SESSION? You don't use it
from one page to the next.
Also, I don't see a call to session_start().
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================