Jump to content

Archived

This topic is now archived and is closed to further replies.

dingus

help with veriable links

Recommended Posts

hello i am trying to set up a link that not only loads a new page but i also want to set a veriable on that page based on the link that iwas clicked on EG you have 4 links "dogs,cats,birds,fist" and you want all 4 links to point to the same page (EG. Example.php)

when you click the dogs link i want to set $animal to dogs on example.php

where as when you click on the cats it would set $animal to cats on example.php

and so on

if some one could please give me a code example or advice to help me with this because i spend over 8 hours today trying to google up the answer thank you

Share this post


Link to post
Share on other sites
put the var in the link address like this

example.php?animal=cat
example.php?animal=dog
etc

then in your script you set the var

$animal = $_GET['animal']

the other option is using javascript, but I wont go into that

Share this post


Link to post
Share on other sites
yes samething what drumm said...

example.php?animal=cat
example.php?animal=dog
$sec = $_POST['animal'];
if($sec == "cat")
{

//cat section
}
else if($sec == "dog")
{

//dog section
}
else
{
//Default page with just links
}

Share this post


Link to post
Share on other sites
Best way is a switch statement:
[code=php:0]switch(@$_GET['animal'])
{
    case 'cat':
    case 'dog':
        $animal = $_GET['animal'];
    break;
    default:
        $animal = '';
    break;
}
echo $animal . "<br />\n";
[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.