Jump to content

If Statement From Hyperlink Clicked


yandoo

Recommended Posts

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 :)

Link to comment
https://forums.phpfreaks.com/topic/271596-if-statement-from-hyperlink-clicked/
Share on other sites

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.

Archived

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

×
×
  • Create New...

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.