SirChick Posted October 29, 2007 Share Posted October 29, 2007 Say you have: <a href="ukroaddriving.php">road 1</a> <a href="ukroaddriving.php">road 2</a> <a href="ukroaddriving.php">road 3</a> is there a way to use php to check which of the 3 links was clicked using if statements? Quote Link to comment https://forums.phpfreaks.com/topic/75205-solved-php-to-check-html-link/ Share on other sites More sharing options...
Dragen Posted October 29, 2007 Share Posted October 29, 2007 Why don't you use GET variables to tell the file what was clicked. Something like: <a href="ukroaddriving.php?road=1">road 1</a> <a href="ukroaddriving.php?road=2">road 2</a> <a href="ukroaddriving.php?road=3">road 3</a> Then on ukroaddriving.php have a check to read the GET var: <?php $road = $_GET['road']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/75205-solved-php-to-check-html-link/#findComment-380372 Share on other sites More sharing options...
SirChick Posted October 29, 2007 Author Share Posted October 29, 2007 i been told that get is a bad idea to use and should use post? can post be done also or only get? Quote Link to comment https://forums.phpfreaks.com/topic/75205-solved-php-to-check-html-link/#findComment-380383 Share on other sites More sharing options...
Dragen Posted October 29, 2007 Share Posted October 29, 2007 Post could be used, but it's needless hassle for something like that. I presume all you're doing is checking which link is clicked so you can display the correct information? I'd use a simple GET var. Quote Link to comment https://forums.phpfreaks.com/topic/75205-solved-php-to-check-html-link/#findComment-380388 Share on other sites More sharing options...
cooldude832 Posted October 29, 2007 Share Posted October 29, 2007 Get isn't "Bad" it is just different from post. they both have unique properties to them that you should investigate before you make an assumption about them. I use GET a lot on my sites and I use POST a lot less on my sites only because I don't have a need for it. This site uses GET and you can clear see it isn't "bad" Quote Link to comment https://forums.phpfreaks.com/topic/75205-solved-php-to-check-html-link/#findComment-380392 Share on other sites More sharing options...
SirChick Posted October 29, 2007 Author Share Posted October 29, 2007 well the idea is : <a href="ukroaddriving.php?road=1">road 1</a> <a href="ukroaddriving.php?road=2">road 2</a> <a href="ukroaddriving.php?road=3">road 3</a> if road 1 { echo 'road 1'} elseif road 2{ echo 'road 2'} }else{ echo 'road 3' } thats the principal idea just by the page refreshing rather than going to a diffrent process page and then reloading the page to display it... Quote Link to comment https://forums.phpfreaks.com/topic/75205-solved-php-to-check-html-link/#findComment-380398 Share on other sites More sharing options...
Dragen Posted October 29, 2007 Share Posted October 29, 2007 Yeah that would work, but use the GET vars, also a switch might be good: <a href="ukroaddriving.php?road=1">road 1</a> <a href="ukroaddriving.php?road=2">road 2</a> <a href="ukroaddriving.php?road=3">road 3</a> if(isset($_GET['road']){ switch($_GET['road']){ case '1': echo 'road1'; break; case '2': echo 'road2'; break; case '3': echo 'road3'; break; default: echo 'invalid road selected'; break; } } Quote Link to comment https://forums.phpfreaks.com/topic/75205-solved-php-to-check-html-link/#findComment-380400 Share on other sites More sharing options...
cooldude832 Posted October 29, 2007 Share Posted October 29, 2007 so i take it you gave up on my map idea Quote Link to comment https://forums.phpfreaks.com/topic/75205-solved-php-to-check-html-link/#findComment-380403 Share on other sites More sharing options...
SirChick Posted October 29, 2007 Author Share Posted October 29, 2007 Yeah that would work, but use the GET vars, also a switch might be good: <a href="ukroaddriving.php?road=1">road 1</a> <a href="ukroaddriving.php?road=2">road 2</a> <a href="ukroaddriving.php?road=3">road 3</a> if(isset($_GET['road']){ switch($_GET['road']){ case '1': echo 'road1'; break; case '2': echo 'road2'; break; case '3': echo 'road3'; break; default: echo 'invalid road selected'; break; } } if i did the if statements on a different php file would it automatically carry the get accross when the link is pressed or is it to only the page in which the code is on ? Quote Link to comment https://forums.phpfreaks.com/topic/75205-solved-php-to-check-html-link/#findComment-380512 Share on other sites More sharing options...
Dragen Posted October 29, 2007 Share Posted October 29, 2007 If it's a different file then You'll need to pass the GET across, unless the other file is 'include'd in the file which has the GET in the url. Quote Link to comment https://forums.phpfreaks.com/topic/75205-solved-php-to-check-html-link/#findComment-380516 Share on other sites More sharing options...
SirChick Posted October 29, 2007 Author Share Posted October 29, 2007 im lost now.. say one file is test.php which has <a href="process.php?road=1">road 1</a> then process.php has: if(isset($_GET['road']){ switch($_GET['road']){ case '1': echo 'road1'; break; case '2': echo 'road2'; break; case '3': echo 'road3'; break; default: echo 'invalid road selected'; break; } } would it work ? Quote Link to comment https://forums.phpfreaks.com/topic/75205-solved-php-to-check-html-link/#findComment-380521 Share on other sites More sharing options...
Dragen Posted October 29, 2007 Share Posted October 29, 2007 oh, yeah. that would work fine. Sorry I thought you meant collecting the GET on one page and then sending it to another Quote Link to comment https://forums.phpfreaks.com/topic/75205-solved-php-to-check-html-link/#findComment-380522 Share on other sites More sharing options...
SirChick Posted October 29, 2007 Author Share Posted October 29, 2007 ok thankyou Dragen Quote Link to comment https://forums.phpfreaks.com/topic/75205-solved-php-to-check-html-link/#findComment-380523 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.