Skip to main content
October 1, 2010
Question

Dynamic <a href> tag

  • October 1, 2010
  • 2 replies
  • 7978 views

I have a page that contains about 110 definitions related to the site's product. These are pulled from a database. My question is, on the old site he had <a href> tags so you could go to specific terms that were of course alphabetized. Since these are now pulled from a database, I'm not sure how to set a link to each one that would be in alphabetical order.

In other words. the first term is "Ambient Lighting". At the top of the page is the alphabet listed and when you click on "A" it takes you to the list of terms that begin with an "A".

Maybe there is a better way of doing this. If anyone has any ideas, I would appreciate any help. Thanks in advance!

    This topic has been closed for replies.

    2 replies

    ilssac
    Inspiring
    October 1, 2010

    You may also be asking how to write an HTML anchor tag.

    Those look like this.

    <a href="#A-anchor">A</a>

    <a href="#B-anchor">B</a>

    <a id="A-anchor">A items</a>

    <!--- list of a items --->

    <a id="B-anchor">B items</a>

    <!--- list of b items --->

    NOTE:

    If you have the first anchor links inside of a ColdFusion <cfoutput...></cfoutpout> block, you must escape the # symbols.

    I.E. <cfoutput><a href="##A-anchor">A</a></cfoutput>

    October 1, 2010

    ilssac wrote:

    You may also be asking how to write an HTML anchor tag.

    Those look like this.

    <a href="#A-anchor">A</a>

    <a href="#B-anchor">B</a>

    <a id="A-anchor">A items</a>

    <!--- list of a items --->

    <a id="B-anchor">B items</a>

    <!--- list of b items --->

    NOTE:

    If you have the first anchor links inside of a ColdFusion <cfoutput...></cfoutpout> block, you must escape the # symbols.

    I.E. <cfoutput><a href="##A-anchor">A</a></cfoutput>

    No I understand how to create anchor tags. Thanks. I just dont know how to use them on Dynamic data.

    ilssac
    Inspiring
    October 1, 2010

    <cfoutput query="rsTerms" group="letterField">

    <a id="#rsTerms.letterField#">#rsTerms.letterField# Items</a>

    <cfoutput>

    #rsTerms.terms# #rsTerms.definitions#<br>
    </cfoutput>

    </cfoutput>

    You will need to add something to your query to creat the letterField using what ever string functions your database supports to extract the first letter of each term.

    Inspiring
    October 1, 2010

    Use an order by clause in your query.

    Use cfoutput with a query attribute to build your anchor tags.

    October 1, 2010

    Hi Dan, thanks for the reply. Not exactly sure I understand what you mean. Here is my query, which has an order by clause using Terms.

    function(){return A.apply(null,[this].concat($A(arguments)))}

    <cfquery name="rsTerms" datasource="rlbulbs">
    SELECT rlbterms.terms, rlbterms.definitions
    FROM rlbterms
    ORDER BY rlbterms.terms
    </cfquery>

    Could you please elaborate a little further on query attribute? Thanks again!

    Inspiring
    October 1, 2010

    I had the impression you wanted your data sorted alphabetically.  If your current order by clause achieves that, good.  If not, change it.

    For the next question.

    <cfoutput query="yourquery">