ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old August 23rd, 2004, 01:25 PM
RobertR RobertR is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 17 RobertR User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
terms in alphabetical order

Hi there,
I am building a glossary and have included all terms in a table. I have a query that displays all terms in alphabetical order (see below). My question is how do I "break up" the list of terms by including a visual break (maybe an <hr> or a big letter) after all terms that begin with a, all terms that begin with b, etc. so that the list is not one gigantic array of words?

<cfquery name="get_terms" datasource="glossary">
select termID, term, definition
from terms
order by term
</cfquery>

<cfoutput query="get_terms"><a href="definition.cfm?termID=#termID#">#term#</a><br></cfoutput>

Thanks,
Robert

Reply With Quote
  #2  
Old August 23rd, 2004, 01:32 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,626 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 10 h 6 m 34 sec
Reputation Power: 53
You can do this with conditional logic, something like

<cfset currentLetter = "A" />
<cfif left( myTerm, 1 ) neq currentLetter>
<cfset currentLetter = getNextLetter( currentLetter )>
....do <hr> or whatever....
</cfif>

You could write getNextLetter() as a UDF that returns the next letter of the alphabet...
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian.
How to Post a Question in the Forums

Reply With Quote
  #3  
Old August 23rd, 2004, 02:36 PM
RobertR RobertR is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 17 RobertR User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Uh...thanks for the info. The advice sounds like something that would work. However, I've never created a user-defined function...Can you give me an example or point me to the right reference?
Thanks,
R

Reply With Quote
  #4  
Old August 23rd, 2004, 02:48 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,626 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 10 h 6 m 34 sec
Reputation Power: 53
Something like this:

Code:
<cffunction name="getNextLetter">
	<cfargument name="aLetter" type="string" required="Yes" />
	<cfset asciiValue = asc( arguments.aLetter ) />
	<cfif asciiValue lte 89>
		<cfreturn chr( asciiValue + 1 ) />
	<cfelse>
		<cfreturn "" />	
	</cfif>
</cffunction>


The CF documentation has an entire section on UDF's.

Reply With Quote
  #5  
Old August 23rd, 2004, 03:25 PM
globeuser globeuser is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 10 globeuser User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
http://livedocs.macromedia.com/coldfusion/6.1/htmldocs/udfs2.htm#wp1088159

Reply With Quote
  #6  
Old August 25th, 2004, 05:51 PM
RobertR RobertR is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 17 RobertR User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thank you so much for this function!!! It almost works :-) The only thing that happens is that at the end of each group of words that start with a letter (let's say A), there is one word left that starts with B and then the <hr> appears and then the list of words that start with B... Is there something I am doing wrong in displaying the output? Here's is the code I have where getnextLetter is the function that you defined.

<cfoutput query="get_terms"><a href="definition.cfm?termID=#termID#">#term#</a><br>
<cfif left( term, 1 ) neq currentLetter>
<cfset currentLetter = getNextLetter( currentLetter )>
<hr>
</cfif>
</cfoutput>

Reply With Quote
  #7  
Old August 25th, 2004, 07:46 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,626 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 10 h 6 m 34 sec
Reputation Power: 53
Does this work?

<cfoutput query="get_terms">
<cfif left( term, 1 ) neq currentLetter>
<cfset currentLetter = getNextLetter( currentLetter )>
<hr>
</cfif>
<a href="definition.cfm?termID=#termID#">#term#</a><br>
</cfoutput>

Reply With Quote
  #8  
Old August 26th, 2004, 12:59 PM
RobertR RobertR is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 17 RobertR User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
It sure does!!! Thank you!
R

Reply With Quote
  #9  
Old August 31st, 2004, 12:33 PM
RobertR RobertR is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 17 RobertR User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
One more question for you - remember the getnextletter function that you designed for me? (see below).
<cffunction name="getNextLetter">
<cfargument name="aLetter" type="string" required="Yes" />
<cfset asciiValue = asc( arguments.aLetter ) />
<cfif asciiValue lte 89>
<cfreturn chr( asciiValue + 1 ) />
<cfelse>
<cfreturn "" />
</cfif>
</cffunction>
I still get an error, which says
Just in time compilation error

Invalid token found on line 11 at position 16. ColdFusion was looking at the following text:

(

I guess it does not like the parenthesis in <cfreturn chr( asciiValue + 1 ) />... Any suggestions?

Thank you so much again! (this is weird because it works on my localhost but not on the server...)

Reply With Quote
  #10  
Old August 31st, 2004, 12:45 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,626 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 10 h 6 m 34 sec
Reputation Power: 53
No, it runs fine for me too. Something else is wrong because it's impossible that it runs correctly locally and fails on another server, unless the other server is running another version of CF?

Reply With Quote
  #11  
Old September 1st, 2004, 10:27 AM
DeepDown DeepDown is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Netherlands
Posts: 99 DeepDown User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 1 m 8 sec
Reputation Power: 6
Quote:
Originally Posted by RobertR
Hi there,
I am building a glossary and have included all terms in a table. I have a query that displays all terms in alphabetical order (see below). My question is how do I "break up" the list of terms by including a visual break (maybe an <hr> or a big letter) after all terms that begin with a, all terms that begin with b, etc. so that the list is not one gigantic array of words?

<cfquery name="get_terms" datasource="glossary">
select termID, term, definition
from terms
order by term
</cfquery>

<cfoutput query="get_terms"><a href="definition.cfm?termID=#termID#">#term#</a><br></cfoutput>

Thanks,
Robert


If the thing with the function doesn't work, you could use the following strategy. Depending on the database-system you work with the SQL will be slightly different, but the basic idea would be this:

<cfquery name="get_terms" datasource="glossary">
select termID, term, definition, LEFT(term,1) as FirstLetter
from terms
order by term
</cfquery>

<cfoutput query="get_terms" group="FirstLetter">
#FirstLetter#
<cfoutput>
<a href="definition.cfm?termID=#termID#">#term#</a><br></cfoutput>
<hr>
</cfoutput>
__________________
** Don't expect me to code your needs, but if I am able to help, I'm willing. Shout, grab and use the hand!
** Man can no more own the land we walk upon, as they can lay claim on the air that we breath
** DeepDown I'm addicted to structures.... ohw and music
** Almost forgot I had an account here [*o*]

Reply With Quote
  #12  
Old September 1st, 2004, 10:29 AM
DeepDown DeepDown is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Netherlands
Posts: 99 DeepDown User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 1 m 8 sec
Reputation Power: 6
Oh you'll end up with a HR at the end, which you can skip by:

<cfif currentrecord neq recordcount><HR></cfif>

Reply With Quote
  #13  
Old September 1st, 2004, 10:51 AM
RobertR RobertR is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 17 RobertR User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thank you sooooooooooo much! This worked out great!!!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > terms in alphabetical order


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |