dingus Posted July 2, 2006 Share Posted July 2, 2006 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.phpand so onif 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 Link to comment https://forums.phpfreaks.com/topic/13462-help-with-veriable-links/ Share on other sites More sharing options...
Drumminxx Posted July 2, 2006 Share Posted July 2, 2006 put the var in the link address like thisexample.php?animal=catexample.php?animal=dogetcthen in your script you set the var$animal = $_GET['animal']the other option is using javascript, but I wont go into that Link to comment https://forums.phpfreaks.com/topic/13462-help-with-veriable-links/#findComment-52008 Share on other sites More sharing options...
karthikeyan_coder Posted July 2, 2006 Share Posted July 2, 2006 yes samething what drumm said...example.php?animal=catexample.php?animal=dog$sec = $_POST['animal'];if($sec == "cat"){//cat section}else if($sec == "dog"){//dog section}else{//Default page with just links} Link to comment https://forums.phpfreaks.com/topic/13462-help-with-veriable-links/#findComment-52065 Share on other sites More sharing options...
wildteen88 Posted July 2, 2006 Share Posted July 2, 2006 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] Link to comment https://forums.phpfreaks.com/topic/13462-help-with-veriable-links/#findComment-52081 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.