SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: Anchors in PHP?

  1. #1
    SitePoint Evangelist IJoeR's Avatar
    Join Date
    Feb 2003
    Location
    Somewhere in, MD
    Posts
    400
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Anchors in PHP?

    I need some help.

    I created this website
    http://www.ijwebsites.com/mj/ for a client. And what he wants is when you click on an article from the In the News section, he wants it to work like an "anchor" where when you click the article it brings that article to the top of the page. Right now the way it works is it takes you to the top of the page no matter what article you click.

    So, the question is how would I add this feature? Anyone?

    thanks!
    IJoeR

  2. #2
    SitePoint Addict CeleronXL's Avatar
    Join Date
    Dec 2002
    Location
    United States of America
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anchors are created by <a name="somename">Some Link</a>, and are referended by #somename at the end of the URL.
    So hold me when I'm here
    Right me when I'm wrong
    Hold me when I'm scared
    Love me when I'm gone.

  3. #3
    Non-Member Icheb's Avatar
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    1,474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    An HTML based approach is certainly the way to go here. That way the reader gets to see the article he wants to read and the articles are still sorted by the date they were added.

  4. #4
    SitePoint Evangelist IJoeR's Avatar
    Join Date
    Feb 2003
    Location
    Somewhere in, MD
    Posts
    400
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Let me clarify. I know how to make HTML anchors. What I'm not sure how to do is to implement them in my system I have here because the article titles are pulled dynamically from the database. What I'm thinking is to have the anchor names be the ID #'s that are stored in the database so they'll change with each article that is added. I'm thinking that will work.

  5. #5
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by IJoeR
    Let me clarify. I know how to make HTML anchors. What I'm not sure how to do is to implement them in my system I have here because the article titles are pulled dynamically from the database. What I'm thinking is to have the anchor names be the ID #'s that are stored in the database so they'll change with each article that is added. I'm thinking that will work.
    That's exactly how to do it -- your resulting HTML could look like this:

    HTML Code:
    <a name="articleID1" />
    ...
    <a name="articleID2" />
    ...
    <a name="articleID3" />
    ...
    And links to those pages (generated, again, dynamically):

    HTML Code:
    <a href="http://www.ijwebsites.com/mj/inthenews.php#articleID1">News, news news..</a>
    <a href="http://www.ijwebsites.com/mj/inthenews.php#articleID2">News, news news2..</a>
    <a href="http://www.ijwebsites.com/mj/inthenews.php#articleID3">News, news news3..</a>
    Your PHP code looking like this:

    PHP Code:
    $sql "SELECT * FROM table";
    //...
    $id $row['id'];
    $content $row['content'];
    echo 
    "<a name='articleID$id' />";
    echo 
    $content;
    //... 
    And

    PHP Code:
    $sql "SELECT * FROM table";
    //...
    $id $row['id'];
    $description $row['description'];
    echo 
    "<a href='inthenews.php#articleID$id'>$description</a>"
    My name is Steve, and I'm a super-villian.

  6. #6
    SitePoint Evangelist IJoeR's Avatar
    Join Date
    Feb 2003
    Location
    Somewhere in, MD
    Posts
    400
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes thanks everyone for the help. I guess i was just over-thinking the whole thing. In any case, I got it to work. Thanks!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •