Jump to content
Larry Ullman's Book Forums

Any One Knows How To Use The Name Anchor With Dynamic Url?


Recommended Posts

Hello every one,

 

I have a page with subjects and each subject has comments, but the page shows only few comments for each subjects and there is a link says how many comments there are for the subject and when you click on it, the page reload and shows all the comments for that subject, but it doesn't take me to that subject.

 

Thanks in advance

Link to comment
Share on other sites

Hi Bahaa,

 

You'd really have to show us code to be able to help you. I understand your problem, but it would be complete guess for anyone to tell you what's wrong. Please post the code your using and what it's out putting.

 

Thanks ;)

  • Upvote 1
Link to comment
Share on other sites

bahaa, as Jonathon said, it's hard to imagine exactly what's wrong. As you noted in the title of your post though, I imagine that you're not properly creating the links to the subjects.

 

This sounds like a message board-type thing. Anyway, I imagine you have a separate script used for displaying the content of a subject, right? If that's the case, in each of the links, you'll need to call that script, and then send additional information in the URL that the GET method can use to retrieve the proper subject and its content/comments.

 

Well, hope that helps.

  • Upvote 1
Link to comment
Share on other sites

Depending on how far you want to take it, doing that might be difficult. If you'll notice, the URL is not composed of the standard script-name.php?name=value&name=value syntax.

 

I can't recall exactly (hoping for Larry to step in), but I believe he covers how to do this at the beginning of the second example site in his e-commerce book. Basically, you need to use an .htaccess file, etc. to convert the format of the URL.

 

I think it would be best to start out with the standard format used for the GET method, and once you have that working, then add this additional later on. In the end, the functionality is the same. The only difference is that the URL becomes slightly more "readable" for humans.

  • Upvote 1
Link to comment
Share on other sites

Depending on how far you want to take it, doing that might be difficult. If you'll notice, the URL is not composed of the standard script-name.php?name=value&name=value syntax.

 

I can't recall exactly (hoping for Larry to step in), but I believe he covers how to do this at the beginning of the second example site in his e-commerce book. Basically, you need to use an .htaccess file, etc. to convert the format of the URL.

 

I think it would be best to start out with the standard format used for the GET method, and once you have that working, then add this additional later on. In the end, the functionality is the same. The only difference is that the URL becomes slightly more "readable" for humans.

doing it with this "script-name.php?name=value&name=value syntax" fine .

Link to comment
Share on other sites

Your post has left me confused as to whether you want more advice or not.

 

When you grab all the subjects from the database, grab the IDs as well, and then set those to each of the links. For example:

 

echo '<a href="display_subjects.php?id=' . $row['id'] . '">' . $row['subject_title'] . '</a>\n';

 

Something like that should suffice. You can then use the $_GET superglobal from display_subject.php to grab the appropriate subject and content from the database.

 

Cool?

  • Upvote 1
Link to comment
Share on other sites

It sounds to me like bahaa is looking for how to add a named anchor to an URL containing a query string. The named anchor needs to go last. Something like:

echo '<a href="display_subjects.php?id=' . $row['id'] . '#namedAnchor">' . $row['subject_title'] . '</a>\n';

  • Upvote 1
Link to comment
Share on other sites

It sounds to me like bahaa is looking for how to add a named anchor to an URL containing a query string. The named anchor needs to go last. Something like:

echo '<a href="display_subjects.php?id=' . $row['id'] . '#namedAnchor">' . $row['subject_title'] . '</a>\n';

Yes, this is what I want.

I will try it, and let you know.

Thanks for your helps guys.

Link to comment
Share on other sites

Oh, you meant you wanted to jump to an anchor on a page? I see. Well, if that's the case, then you probably need to completely restructure your URL. I thought you were clicking on a subject link, and then loading all the details of that subject onto a separate page.

 

Actually, bahaa, I'm confused now. If you get it working, then great, but if you have the time, could you please explain exactly what you want. Thanks.

  • Upvote 1
Link to comment
Share on other sites

Oh, you meant you wanted to jump to an anchor on a page? I see. Well, if that's the case, then you probably need to completely restructure your URL. I thought you were clicking on a subject link, and then loading all the details of that subject onto a separate page.

 

Actually, bahaa, I'm confused now. If you get it working, then great, but if you have the time, could you please explain exactly what you want. Thanks.

Yes, I wantt to jump to a named anchor on the page

Link to comment
Share on other sites

If you're jumping to an anchor on the same page, then all you need is the following:

 

echo '<a href="#' . $row['anchor_name'] . '">Link name here</a>';

 

And if the anchor is on another page:

 

echo '<a href="otherscript.html#' . $row['anchor_name'] . '">Link name here</a>';

 

Hope that helps.

  • Upvote 1
Link to comment
Share on other sites

 Share

×
×
  • Create New...