Jump to content


Photo

help with veriable links


  • Please log in to reply
3 replies to this topic

#1 dingus

dingus
  • Members
  • PipPipPip
  • Advanced Member
  • 148 posts

Posted 02 July 2006 - 03:30 PM

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
Best Mobile Store i ever used.

#2 Drumminxx

Drumminxx
  • Members
  • PipPipPip
  • Advanced Member
  • 92 posts
  • LocationUSA

Posted 02 July 2006 - 03:40 PM

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
:: gucci.com ::
:: blockbuster.com ::

--------------------

#3 karthikeyan_coder

karthikeyan_coder
  • Members
  • PipPipPip
  • Advanced Member
  • 201 posts

Posted 02 July 2006 - 05:18 PM

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
}

www.karthi.us

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 02 July 2006 - 05:42 PM

Best way is a switch statement:
switch(@$_GET['animal'])
{
    case 'cat':
    case 'dog':
        $animal = $_GET['animal'];
    break;
    default:
        $animal = '';
    break;
}
echo $animal . "<br />\n";





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users