473,385 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Help with session count code

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']--;
}

Nov 2 '07 #1
7 2517
On Nov 2, 7:19 pm, Chris <matchett...@googlemail.comwrote:
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?"
Nov 2 '07 #2
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.
Nov 3 '07 #3
On 3 Nov, 06:12, Chris Gorospe <ch...@ekast.comwrote:
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

Nov 3 '07 #4
On 3 Nov, 06:12, Chris Gorospe <ch...@ekast.comwrote:
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

Nov 3 '07 #5
Chris wrote:
On 3 Nov, 06:12, Chris Gorospe <ch...@ekast.comwrote:
>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.
js*******@attglobal.net
==================

Nov 3 '07 #6
On 3 Nov, 13:44, Jerry Stuckle <jstuck...@attglobal.netwrote:
Chris wrote:
On 3 Nov, 06:12, Chris Gorospe <ch...@ekast.comwrote:
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--
<p><a href="index.php?lstWk=1">&lt;&lt;</aBack Next <a
href="index.php?nxtWk=1">&gt;&gt;</a>
<?=$_SESSION['weeknumber']; ?>
</p>

Nov 3 '07 #7
Chris wrote:
On 3 Nov, 13:44, Jerry Stuckle <jstuck...@attglobal.netwrote:
>Chris wrote:
>>On 3 Nov, 06:12, Chris Gorospe <ch...@ekast.comwrote:
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--
<p><a href="index.php?lstWk=1">&lt;&lt;</aBack Next <a
href="index.php?nxtWk=1">&gt;&gt;</a>
<?=$_SESSION['weeknumber']; ?>
</p>

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.
js*******@attglobal.net
==================

Nov 3 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Alexandre MELARD | last post by:
Hi, My name is alexandre, I am 4th year student at the Napier university of edinburgh. I am finishing my year and do a presentation of my honours project next wednesday (the 5th of May). I am...
28
by: stu_gots | last post by:
I have been losing sleep over this puzzle, and I'm convinced my train of thought is heading in the wrong direction. It is difficult to explain my circumstances, so I will present an identical...
0
by: john | last post by:
Hi,All MS Tech Gurus: I need your help!!! It is the second time I post this message, I need get some feedback ASAP, Please Help!! Thanks a lot in advance. John I have a csharp method, using...
5
by: Marc Bishop | last post by:
I'm trying to get this to work but i'm at a loss as to how. i've searched google without much help code Dim ArrCart As new ArrayList() ArrCart = CType(Session("sesCart"), ArrayList)...
4
by: steroche | last post by:
I would REALLY appreciate help please please please! Im sure it is probably blindingly obvious to most of you but I am totally in the dark here!I am lost - i thought i had finally figured out this...
8
by: Bruno Alexandre | last post by:
Hi guys, I'm using a session to save an ArrayList, so I do not read Database everytime user reload the page or enter the site (the Data is consistent for all entire session time when the user is...
0
by: TRB_NV | last post by:
I'd been using an Access database based shopping cart, but wanted to change it so that it would use session variables. I have a form that's submitted to a page called addtocart.asp that contains...
0
by: Mike Collins | last post by:
I someone can please help, I am about at an end in trying to figure this out. I am adding some dynamic controls to my page (I found out that I was supposed to be doing that in the oninit event,...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
2
by: StevenChiasson | last post by:
For the record, not a student, just someone attempting to learn C++. Anyway, the problem I'm having right now is the member function detAddress, of object controller. This is more or less, your...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.