Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-04-25 21:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found