Connor Neville
Connor Neville

Reputation: 1078

PHP and A id in URL?

In part of a web page, I currently link to a part of the webpage using . In other words, I link to something like:

<a href="index.php#blog">Link 1</a>

However, on that same link I want to include a PHP variable, which would normally look like

<a href="index.php?id=1">Link 2</a>

Combining the two in either order just makes the page refresh, neither scrolling properly or taking the php variable. How can I use the two simultaneously?

Upvotes: 2

Views: 1639

Answers (2)

DarkDevine
DarkDevine

Reputation: 1047

When you're on the same page as the URL in your anchor, regardless of #'s value (It's called the "fragment"), the page won't even refresh, it will scroll up in hope to find an anchor that has the fitting name for the fragment

The URL fragment (everything behind # at the end of an URL) is a client-side thing, PHP won't be able to do anything with it

Upvotes: 1

Andrew
Andrew

Reputation: 1357

You can concatenate the two together, just put the hash last because that is not sent to the webserver (it will be used by the browser to jump to a certain part of the page):

<a href="index.php?id=1#blog">Link 1</a>

Upvotes: 6

Related Questions