Newbie Q: Increment of 1 in a variable by clicking a link?
Posted: Sat Mar 01, 2008 12:44 am
Hi,
I'm an absolute newbie in PHP and my "problem" is probably not an exciting one for most people here, but I would appreciate it very much if someone could provide me with a solution.
I'm not even sure I can explain my problem properly (Danish newbie..
), but I will try.
Basically I'm trying to figure out how to make a good page navigation system so that no matter how many pages you have, you will stay on the index page the whole time, but with different main content.
I got an idea to do this if I can manage to make an increment of 1 in a variable when a link is clicked.
In another link I want to make an increment of 10 in the same variable.
This is what I tried so far:
<a href="index.php?sidetillaeg=1">add 1</a>
and
<a href="index.php?sidetillaeg=10">add 10</a>
The plan is to make 2 more links subtracting 1 and 10 instead of adding them.
In the index.php file I then used...
$sidestyrer = $_GET["sidetillaeg"];
...to make sure that PHP has the correct number (1 or 10) in a variable it understands, here named $sidestyrer.
The next thing I do is this:
$page = $page + $sidestyrer;
The $page variable always holds the number of the page I want to output.
All this actually works for me, but only the first time I click a link! After that any click on the same link will output the same page as previous.
And I suppose the reason must be that the URL becomes "index.php?sidetillaeg=1" where it should actually be "index.php?"?
How can I make a variable increase with a value of 1 everytime I click a certain link and then send the user to the same page?
All help is appreciated, thank you.
- cmarc
I'm an absolute newbie in PHP and my "problem" is probably not an exciting one for most people here, but I would appreciate it very much if someone could provide me with a solution.
I'm not even sure I can explain my problem properly (Danish newbie..
Basically I'm trying to figure out how to make a good page navigation system so that no matter how many pages you have, you will stay on the index page the whole time, but with different main content.
I got an idea to do this if I can manage to make an increment of 1 in a variable when a link is clicked.
In another link I want to make an increment of 10 in the same variable.
This is what I tried so far:
<a href="index.php?sidetillaeg=1">add 1</a>
and
<a href="index.php?sidetillaeg=10">add 10</a>
The plan is to make 2 more links subtracting 1 and 10 instead of adding them.
In the index.php file I then used...
$sidestyrer = $_GET["sidetillaeg"];
...to make sure that PHP has the correct number (1 or 10) in a variable it understands, here named $sidestyrer.
The next thing I do is this:
$page = $page + $sidestyrer;
The $page variable always holds the number of the page I want to output.
All this actually works for me, but only the first time I click a link! After that any click on the same link will output the same page as previous.
And I suppose the reason must be that the URL becomes "index.php?sidetillaeg=1" where it should actually be "index.php?"?
How can I make a variable increase with a value of 1 everytime I click a certain link and then send the user to the same page?
All help is appreciated, thank you.
- cmarc