Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I've thrown together a web front end for a database of terms that some users have asked me to compile for them. The database is very small, and consists of id,term,description.

The front end simply builds a list of the terms with named anchors that link to the full summary of the term lower in the page. It basically looks like this:

Pacifier Pacify Package Packing Pacifier | top | Edit Description and summary of Pacifier Pacify | top | Edit Description and summary of Pacify Package | top | Edit Description and summary of Package Packing | top | Edit Description and summary of Packing

So clicking on Pacifier with the named anchor, will bring you to the section summary for Pacifier. So far, so good...

What has been suggested, since the list of terms can get very long, is to create some named anchors which will "warp" to specific sections in the page. For example, <a href="#Pa">Pa</a> would jump you to the part of the page that contains terms that start with "Pa". <a href="#Pe">Pe</a> would jump lower to the section of terms beginning with "Pe", etc.

I can cut down the amount of vertical scrolling through a long list, by making them "Pa", "Pe", "Pi", "Po", "Pu", for each letter of the alphabet ($letter . [aeiou];)

The problem I'm having, is that my query is in a $sth->fetch() loop that prints each term out of the database. In this construct, how do I "slice" each term coming out, and determine when the first two letters change from "Pa" to "Pe", and set a named anchor directly before the change?

I can't quite figure out the logic to make that happen, programmatically.


In reply to Programmatically building named anchors to warp to sections by hacker

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others making s'mores by the fire in the courtyard of the Monastery: (3)
    As of 2021-01-25 23:36 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Notices?