SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Addict sstaubin01's Avatar
    Join Date
    Nov 2000
    Location
    Ont, Canada
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm creating a array in php on one page and want to pass all occurances of the array to another page using the <a> tag. Can someone tell me how to do this. Thanks.

  2. #2
    SitePoint Wizard silver trophy Karl's Avatar
    Join Date
    Jul 1999
    Location
    Derbyshire, UK
    Posts
    4,411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Try this:
    Code:
    $data = serialize( $array );
    echo "<a href='/page.php?data=$data'>Go To Page</a>";
    then to get the info back use:
    Code:
    $array = unserialize( $data );
    Karl Austin :: Profile :: KDA Web Services Ltd.
    Business Web Hosting :: Managed Dedicated Hosting
    Call 0800 542 9764 today and ask how we can help your business grow.

  3. #3
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Don't think that is gonna work you mave to use a from and make a hidden input and then submit the form somehow.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  4. #4
    SitePoint Wizard silver trophy Karl's Avatar
    Join Date
    Jul 1999
    Location
    Derbyshire, UK
    Posts
    4,411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    True, it does depend on the aray not storing huge amounts of data. The other option is to use PHPs session functions and store the serilized array in a session variable.
    Karl Austin :: Profile :: KDA Web Services Ltd.
    Business Web Hosting :: Managed Dedicated Hosting
    Call 0800 542 9764 today and ask how we can help your business grow.

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried the serialize() aproach but the serialized string contains more than one character that the browser does not like in a query string, I think sessions would be the best way to go
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  6. #6
    SitePoint Addict sstaubin01's Avatar
    Join Date
    Nov 2000
    Location
    Ont, Canada
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I thought I would be able to reference all occurances of an array and be able to pass that variable. Mabye I should make the call again on the new page. I was just trying to avoid the call since I already had the information from a call in the first page.

    Sorry I took so long to respond. I tried using serialize last night and it didn't work as Freddy stated.

    I started looking into Sessions and it seems complex, more complex than what i'm trying to accomplish here.

    Any thoughts?

  7. #7
    Grumpy Mole Man Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,067
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sessions aren't that complex really, and if you figure out how to do them you'll find loads of usedul applications. The only downside is that session data won't be passed on if your user doesn't have cookies turned on (unless it's possible to extract the session id and pass it in an <a href> tag - that should work theoretically but I've never seen it done...)

    Check out these tutorials:

    http://www.phpwizard.net/resources/t...ion_intro.html

    http://www.php.net/manual/en/ref.session.php (PHP Manual)

  8. #8
    SitePoint Addict sstaubin01's Avatar
    Join Date
    Nov 2000
    Location
    Ont, Canada
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Skunk. I'll check out the links.

  9. #9
    Don't eat yellow snow spaceman's Avatar
    Join Date
    Mar 2001
    Location
    Melbourne, Australia
    Posts
    1,039
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    An alternative to using serialize()/unserialize with sessions is to use implode()/explode(), eg:

    $session_var=implode("|",$array);
    $array=explode("|",$session_var);

    Make sure you've got your session set up properly first, of course. My approach might have benefits over serialize() because it seems if you want to serialise(), the you have to worry about urlencode() etc. (see: http://www.php.net/manual/en/function.serialize.php)


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
  •