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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.