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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    session inside links 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

    <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
    Regular Coder
    Join Date
    Sep 2008
    Posts
    280
    Thanks
    25
    Thanked 9 Times in 9 Posts
    PHP Code:
    <a href=USA.php?city=detroit></a>
    <
    a href=USA.php?city=newyork></a>

    if(isset(
    $_GET['city']))
    {
    if(
    $_GET['city']=="detroit")
    {
    echo 
    "Detroit";
    }
    elseif(
    $_GET['city']=="newyork")
    {
    echo 
    "New York";
    }

    Something like that im guessing?
    Last edited by snowysweb; 03-08-2009 at 11:03 AM.

  • #3
    Regular Coder
    Join Date
    Sep 2008
    Posts
    280
    Thanks
    25
    Thanked 9 Times in 9 Posts
    also i would lookup the switch function @ php.net instead of else if you are using more than 2.

  • #4
    Regular Coder
    Join Date
    Sep 2008
    Posts
    280
    Thanks
    25
    Thanked 9 Times in 9 Posts
    or create a database where all the info for the citys are in one table and pull them out via there id.

    PHP Code:
    <a href="USA.php?city=1">Detroit</a>
    <
    a href="USA.php?city=2">New York</a>


    $city $_GET['city'];
    $thing mysql_query("SELECT * from `usatable` where id='$city'");
    if(
    mysql_num_rows($thing)!=0)
    {

    $thing_array mysql_fetch_array($thing);
    $city $thing_array["city"];
    $population $thing_array["population"];
    $weather $thing_array["weather"];

    }
    else
    {
    die(
    "No data");

    Code:
    <h1><?php echo $city; ?></h1>
    
    and so on..
    Last edited by snowysweb; 03-08-2009 at 11:18 AM.


  •  

    Posting Permissions

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