Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Banned
    Join Date
    Nov 2007
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Remember Array Contents

    Hi,

    I have the following code, that inserts the ID value of a link into an array, upon the link being clicked. See example link below:


    www.somthing.co.uk/functions.php?id=23

    How do I get the array to remember its contents, so if the browsers back button is used, and another link is clicked, this link should append/add it's id to whats already inside the array?

    What do I need to change in the following code in order for the array to remember its contents:

    Code:
    <?php
    
      $array[] = $id;
      print_r($array);
    
    ?>

  • #2
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    Use sessions:
    PHP Code:
    <?php

    session_start
    ();
    $_SESSION['ids'][] = $id;
    $array = & $_SESSION['ids'];

    /* ... */

    print_r$array );

    ?>

  • #3
    Banned
    Join Date
    Nov 2007
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The above code doesn't work, when I press the "Back" button on my browser, and select a link with a diffrent ID (or even the same ID) all I get is the following: - Wheres the data?

    Array ( [0] => [1] => [2] => [3] => [4] => )

  • #4
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    Try using $_GET['id'] instead of $id. I don't think kbluhm intended for you to take that code literally, but more as an example.

  • #5
    Banned
    Join Date
    Nov 2007
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    How do I check is the array already contains a particular id, and if so display the following message "Already Exists", if not, then add it?

  • #6
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts

  • #7
    New Coder
    Join Date
    Apr 2007
    Posts
    89
    Thanks
    1
    Thanked 2 Times in 2 Posts
    I'd use a cookie to store the data


  •  

    Posting Permissions

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