Almost everybody who uses a data-driven website has a database containing some information about the users. 
I had a database table called "contact" in which user's first name, last name, address, zip, email, phone, fax.... everything was listed.
If you do have something like that and wish to draw and group your contacts by say last names, maybe you will find this tutorial useful. 

___________________________
CREATE FIRST FILE : "dir.cfm" 
___________________________
Create the first file "dir.cfm" 
Then create a cold fusion form. Within the form create 26 buttons with 
NAME= "same for all buttons" and VALUE="alphabets from A-Z" as shown in the example


  <html>
  	<head>
  		<title>DIRECTORY</title>
  	</head>

  <body>
  <cfform action="list.cfm" method="POST" enablecab="Yes">
  
      <input type="hidden" name="option" value="0" />
      <input type="SUBMIT" name="a" value="A" />
      <input type="SUBMIT" name="a" value="B" />
      <input type="SUBMIT" name="a" value="C" />
      <input type="SUBMIT" name="a" value="D" />
      <input type="SUBMIT" name="a" value="E" />
      <input type="SUBMIT" name="a" value="F" />
      <input type="SUBMIT" name="a" value="G" />
      <input type="SUBMIT" name="a" value="H" />
      <input type="SUBMIT" name="a" value="I" />
      <input type="SUBMIT" name="a" value="J" />
      <input type="SUBMIT" name="a" value="K" />
      <input type="SUBMIT" name="a" value="L" />
      <input type="SUBMIT" name="a" value="M" />
      <input type="SUBMIT" name="a" value="N" />
      <input type="SUBMIT" name="a" value="O" />
      <input type="SUBMIT" name="a" value="P" />
      <input type="SUBMIT" name="a" value="Q" />
      <input type="SUBMIT" name="a" value="R" />
      <input type="SUBMIT" name="a" value="S" />
      <input type="SUBMIT" name="a" value="T" />
      <input type="SUBMIT" name="a" value="U" />
      <input type="SUBMIT" name="a" value="V" />
      <input type="SUBMIT" name="a" value="W" />
      <input type="SUBMIT" name="a" value="X" />
      <input type="SUBMIT" name="a" value="Y" />
      <input type="SUBMIT" name="a" value="Z" />

  </cfform>
  
  </body>
  </html>
  

______________________________
CREATE SECOND FILE : "list.cfm" 
______________________________

Then create a second file "list.cfm" with the query and and listing values in it, as follows;

      <!--- this was my query to the directory dsn --->
      
      <cfquery name="dir" datasource="YOUR DSN" dbtype="ODBC">
      	Select *
        from contact
        where contact.l_name like '#form.a#%'
      </cfquery>
  

If you know some basic SQL a% will give you the values starting from "A" b% will give those starting from "B" and so on. You can even tweak the "dir.cfm" page to search by last name or first name. For our purpose here I have only searched by Last Names
      <html>
      	<head>
        	<title>LISTINGS</title>
      	</head>

      <body>
      <div align="center" />
      	<cfinclude template="dir.cfm" />
        <hr />
      	<!--- the rest of it is simple use of cfoutput tags and aligning the query results to you liking. I have done it in a single row of a table. But you may set it to look differently. --->
        
      Found records: <cfoutput>#dir.recordcount#</cfoutput><br />
      <!--- counts number of records found --->
      
      <table width="100%">
      	<tr align="center" valign="middle" bgcolor="eeeeff">
      		<td>COUNT</td>
      		<td>NAME</td>
      		<td>URL</td>
      		<td>EMAIL</td>
      		<td>ADDRESS</td>
      		<td>PHONE</td>
      		lt;/tr> 
      		<cfoutput query="dir">
      		<cfform action="directory.cfm" method="POST" enablecab="Yes"> 
      		<tr bgcolor="###iif(currentrow MOD 2,DE('ffffff'),DE('efefef'))#">
      			<td>#currentrow#</td>
      			<td>#f_name# #l_name#</td>
      			<td>#web_page#</td>
      			<td>#email#</td>
      			<td>
                	#address_1#
      				#address_2#<br>
      				#city#,#state#-#zip#
     			</td>
      			<td>#phone#</td>
      		</tr>
      </cfform>
      </cfoutput>
      </table>
      </div>
      </body>
      </html>
  

About This Tutorial
Author: Anang A Phatak
Skill Level: Intermediate 
 
 
 
Platforms Tested: CF5,CFMX,CF8,CF9,BlueDragon,Railo
Total Views: 88,198
Submission Date: November 07, 2003
Last Update Date: August 25, 2011
All Tutorials By This Autor: 12
Discuss This Tutorial
  • You could also query the contacts on the dir.cfm and output all the first letters of the lastname in your alphabet... avoiding returning the empty lastnames. I doubt anyone's lastname will start with a Z... they're rare and probably not in your contacts DB. :) Also, you could use this:

  • INSTEAD OF ; WE CAN USE A LOOP AND CHR FUNCTION FOR EXAMPLE; I DID NOT REALISE IT WHEN I PUT THIS TUTORIAL UP....EASY !

Advertisement

Sponsored By...
$39.00 - 50 Minute Deep Tissue Massage Dripping Springs, Texas!