yandoo Posted December 4, 2012 Share Posted December 4, 2012 Hi there I was hoping for a little guidance if possible.. On my website I have a small area that shows "Most Popular Articles" and underneath I have 4 hyperlinks: Blogs, Tips, News, Videos. i want it so that if the user clicks the hyperlink it echos the appropriate content below. I'm not entirerly sure if Js is more appropriate for this. In php something like: if (hyperlink 1 is clicked) { echo "hard coded content 1" } else if (hyperlink 2 is clicked) { echo "hard coded content 2" } else if (hyperlink 3 is clicked) { echo "hard coded content 3" } else if (hyperlink 4 is clicked) { echo "hard coded content 4" } I can't quite get my head around how to do this because as the hyperlink is clicked a variable is parsed to the same page so that can then this variable be used in the statement. If anyone could advise that would be super. Thank you Quote Link to comment https://forums.phpfreaks.com/topic/271596-if-statement-from-hyperlink-clicked/ Share on other sites More sharing options...
MDCode Posted December 4, 2012 Share Posted December 4, 2012 Php can not tell if a hyperlink was clicked. Javascript will work better for this (I suggest jquery, but that's just me) Quote Link to comment https://forums.phpfreaks.com/topic/271596-if-statement-from-hyperlink-clicked/#findComment-1397493 Share on other sites More sharing options...
yandoo Posted December 4, 2012 Author Share Posted December 4, 2012 Thank you for your guidance. I can post in the appropriate area. Quote Link to comment https://forums.phpfreaks.com/topic/271596-if-statement-from-hyperlink-clicked/#findComment-1397501 Share on other sites More sharing options...
Christian F. Posted December 4, 2012 Share Posted December 4, 2012 If you want to do this with PHP, which I recommend to do before you add JS to the mix, then you'll need to look at GET parameters. They're created by adding a question mark, a key name, an equals sign, and then the value, to the URL. Like this: <a href="test.php?key=value">My link</a> PHP then retrieves the key-value pairs, and saves them to a array so that you can test for conditions. The PHP manual explains more about this. Quote Link to comment https://forums.phpfreaks.com/topic/271596-if-statement-from-hyperlink-clicked/#findComment-1397575 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.