Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

alphabet bookmarks for dynamic list

Status
Not open for further replies.

zmsm18

Programmer
Sep 23, 2005
6
US
I would like the alphabet across the top of the page with a list of names below so the user can click the letter, and it drops down to the corresponding letter in the names list below. However, since the list is dynamically created I don't know how to generate the <a name="letter">letter</a> part into the list. I imagine it would take some type of a script to test if the first character of the name changed, but that is over my head. Any ideas?

Normal HTML:
<a href="#A">A</a>
<a href="#B">B</a>

<a name="A">A</a>
A names
<a name="B">B</a>
B names

What I have is:

<cfoutput query="Getnames">
<tr>
<td>#name#</td>
<td>#phone#</td>
</tr>
</cfoutput>
 
cfqueries:
GetIndex
SELECT DISTINCT left(name,1) as index_letter
FROM MyTable
ORDER BY index_letter
GetNames
SELECT DISTINCT left(name,1) as index_letter,
[name],phone
FROM MyTable
ORDER BY index_letter, name

<CFOUTPUT query="GetIndex">
<a href="###index_letter#">#index_letter#</a>
</CFOUTPUT>

<CFOUTPUT query="getNames" GROUP="index_letter">
<a name="###index_letter#">#index_letter#</a><br>
<cfoutput>
#name# #phone#<br>
</cfoutput>
</cfoutput>

HTH,




Phil Hegedusich
Senior Programmer/Analyst
IIMAK
-----------
I'm not as think as you confused I am.
-----------
Flabbergasted (a.): Amazed at how much weight one has gained.
-----------
Oyster (n.): One who sprinkles their conversation with Yiddish expressions.
 
Something like this should work if you don;t want all the names on the screen at once (like if you have a lot of names to display...) fix the queries to match your database, and the filenames in the hrefs to match yours.

Code:
<cfparam name="url.index" default="a">

<cfquery dsn name="qIndex">
 SELECT 
  SELECT DISTINCT left(name,1) as index_letter
 FROM [table]
 ORDER BY index_letter
</cfquery>


<cfquery dsn name="qNames">
 SELECT 
  id,name	
 FROM [table]
 WHERE left(name,1) EQ url.index
</cfquery>

<cfoutput query="qIndex">
	<a href="index.cfm?index=#index_letter#">#index_letter#</a>
</cfoutput>

<cfoutput query="qNames">
	<a href="view_name.cfm?id=#id#">#name#</a><br/>
</cfoutput>


If you want to display all the names on screen at once, like the first example, you can do it with one query too keep it simple.

Code:
getNames
SELECT 
 left(name,1) as index_letter
 ,name
 ,phone
FROM MyTable
ORDER BY index_letter, name

<CFOUTPUT query="getNames" GROUP="index_letter">
<a href="###index_letter#">#index_letter#</a>
</CFOUTPUT>
<hr/>


<CFOUTPUT query="getNames" GROUP="index_letter">
<a name="###index_letter#">#index_letter#</a><br>
<cfoutput>
#name# #phone#<br>
</cfoutput>
<br>
</cfoutput>


neither has been tested.... but thats the idea anyways.

 
Thanks guys,
Those examples worked great. I had to do a little manipulating to get the output in table columns for presentation, but once I got that it works exactly the way I wanted.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top