0

I found this tutorial that explains what I want to do using html but when I echo out the code with a get variable there is no affect to the page. I would use, for example, the following code:

echo "<a href='post.php?id=".$id."#Comments'>Click here to go to the comments</a>";



echo "<a title='Comments'>Comments</a>";

I presume the problem is to do with the get variable, so would I have to end it, some how, before using the # symbol?

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
Yesterday
  • 561
  • 1
  • 15
  • 31

2 Answers2

3

The problem actually lies in your HTML, because the anchor should be parsed correctly by browsers regardless of the query string.

Page anchors use the name attribute instead of the title attribute:

<a name='Comments'>Comments</a>

You can also apply this to the id attribute of any element:

<h2 id='Comments'>Comments</h2>
BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
  • 3
    +1 for speed, but you're better sticking with just `id`. See: http://stackoverflow.com/questions/484719/html-anchors-with-name-or-id – thirtydot Feb 27 '11 at 18:57
  • That's strange... I was even following a tutorial! I think that's one of the stupidist mistakes I've made since staring php!! I just assumed it was something to do with the php because the html would have been too simple to make a mistake... obviously it wasn't. – Yesterday Feb 27 '11 at 18:58
0

To define jump-labels you have to set a name and/or id-attribute:

echo "<a title='Comments' name='Comments' id='Comments'>Comments</a>";
Floern
  • 33,559
  • 24
  • 104
  • 119