Results 1 to 2 of 2

Thread: session in a link or database?

  1. #1
    Join Date
    Mar 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default session in a link or database?

    Heres a curly one for yous.
    I have about 20 links on a page that I need to have a variable associated with it
    Ie: if you click on the link <a href=USA.php>NEW YORK</A> it will take you to USA.php but display the city of New York at the top of the page. the next link would be <a href=USA.php>Detroit</A> this would also take you to the USA.php but would display Detroit at the top of the page and so on
    The way I imagine this would work is by something like this
    Code:
    <a href=USA.php<?php[$USA=New York]?> New York </a>
    <a href=USA.php<?php[$USA=Detroit]?> Detroit</a>
    i would then have to pass the variable $USA to a session so that it carrys to the next page and is displayed.

    Am I on the right track or is there a better way of doing this?

    I would also like other things to change not just the name at the top but If i can figure out how to carry a different value for each of 20 or so links/variable across to one page I think I could work the rest out.
    Cheers in advance

  2. #2
    Join Date
    Apr 2008
    Location
    Limoges, France
    Posts
    395
    Thanks
    13
    Thanked 61 Times in 61 Posts

    Default

    No session. No database.

    Code:
    <a href=usa.php?city=new_york> New York </a>
    <a href=usa.php?city=detroit> Detroit</a>
    PHP Code:
    <?php

    // usa.php

    if ( isset($_GET['city']) ) {

        
    $city $_GET['city'];

    } else {

        
    $city // some default

    }

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
  •