Skip to main content
Inspiring
April 27, 2006
Answered

Alphabetical list & Anchor links

  • April 27, 2006
  • 2 replies
  • 697 views
Hello all,

I was trying to create a quick search page using anchor links. I have a table of companies, and I would like to create a quick search anchor links on top.

Can someone guide me with the query and how to create a page which looks like following:

| A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z
0 to 10


Followed by company list alphabetically grouped:

0 to 10

- 7/24/365 company
- 360Commerce

A

- ABC Compnay

- Another company

B

- BigCompany.com

- BallPark Investments Inc.

C

- Cisco Systems, Inc.

Thank you
JT
    This topic has been closed for replies.
    Correct answer JethroTull
    This is the final code:

    2 replies

    May 3, 2006
    add an 'order by letter ASC, company ASC' to the query to make sure the order is correct, then use the NESTED output like was shown. This is requiered for this to work as explained

    this is a simple example that was shown above. see what it's doing?
    <CFOUTPUT QUERY="getNames" GROUP="letter">
    <H3><A NAME="#letter#">#letter#</A></H3>
    <CFOUTPUT>#company#<BR></CFOUTPUT>
    </CFOUTPUT>


    Inspiring
    April 27, 2006
    To start out, you can query and get the first letter this way:

    <CFQUERY NAME="getNames" DATASOURCE="mydsn">
    SELECT company, Left(company, 1) AS letter FROM mytable ORDER BY company
    </CFQUERY>

    Then your output would be like this:

    <CFOUTPUT QUERY="getNames" GROUP="letter">
    <H3><A NAME="#letter#">#letter#</A></H3>
    <CFOUTPUT>#company#<BR></CFOUTPUT>
    </CFOUTPUT>

    To create the anchor links, modify this code to write the output to one variable and add another variable that would write something like this:
    <A HREF="###letter#">#letter#</A> |

    When you're done, display the links and then the lists. You might need to modify this for company names that begin with a number.
    Inspiring
    April 28, 2006
    Thank you for your response.

    I am getting all the companies in the query, but I am not getting all the companies in the output.

    I used the following query * and i used the following output code:

    But i am getting only the first company displayed in the group. (Only one company begining with letter A, one company with B etc).

    A
    A.D.A.M. Inc.
    B
    BackWeb Technologies
    C
    Cabinet NG, Inc.
    D
    Dassault Systems

    What am i doing wrong?

    thank you again.

    JT

    JethroTullAuthorCorrect answer
    Inspiring
    April 28, 2006
    This is the final code: