SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Increments

  1. #1
    SitePoint Member
    Join Date
    Apr 2003
    Location
    Berkshire, UK
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Increments

    I am trying to create a link which will open the same page (using $_SERVER['PHP_SELF']) and which will carry a variable increasing by 1 each time it is loaded. I've tried all sorts of synatx but am getting nowhere. Any ideas out there????

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2002
    Location
    Bristol, UK
    Posts
    2,240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you post the code you've done so far?

    -Sam
    Sam Hastings

  3. #3
    gingham dress, army boots... silver trophy redux's Avatar
    Join Date
    Apr 2002
    Location
    Salford / Manchester / UK
    Posts
    4,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <a href="<?php echo $_SERVER['PHP_SELF'].'?variable='.($_GET['variable']+1);?>">click me again</a>
    re·dux (adj.): brought back; returned. used postpositively
    [latin : re-, re- + dux, leader; see duke.]
    WaSP Accessibility Task Force Member
    splintered.co.uk | photographia.co.uk | redux.deviantart.com

  4. #4
    SitePoint Zealot
    Join Date
    Dec 2001
    Location
    UK
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Should work, unless you are resetting the variable in the same page you are incrementing it.

  5. #5
    SitePoint Enthusiast Darth Cow's Avatar
    Join Date
    Oct 2002
    Location
    Swarthmore, PA, USA
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That code work on my own test page. The only thing I can think of is to make sure that you've defined $_GET['variable'] on the first page, too, or you won't get anything in your link. Something like the code below might help if you put it before your link code (or you can just make sure that variable is always defined in links to the page):
    PHP Code:
    <?php
    if (!isset($_GET['variable'])) {
        
    $_GET['variable'] = 0;
    }
    ?>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •