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:
  #1  
Old January 4th, 2005, 08:16 AM
DjPizat DjPizat is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Location: Mass
Posts: 26 DjPizat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 7 m 33 sec
Reputation Power: 0
Structures: Finding Values

Hey everyone,
I'm fairly new to coldfusion structures and I'm not sure if I'm trying to solve this problem the right way.
I have a list of people. The list will include their name, a pdf path, and letter that begins their last name.

I decided to put this into a nested structure. What i need to do is be able to search the structure to pull out people by the letter for their last name.

For example there will be a drop down with A-Z. Then when someone selects A only those people with last name that begin with A will appear.

This is my code so far. I just don't know how to pull out the index field where people have an "A" or whatever letter in there.
Please help!

<cfset speakers = structNew()>
<cfset speakers.speaker1.name = "Daniel">
<cfset speakers.speaker1.pdf = "Daniel.pdf">
<cfset speakers.speaker1.index = "a">
<cfset speakers.speaker2.name = "Tom">
<cfset speakers.speaker2.pdf = "Tom.pdf">
<cfset speakers.speaker2.index = "b">

<cfloop collection="#speakers#" item="speaker">
<cfloop collection="#speakers[speaker]#" item="key">
#speakers[speaker][key]#<br/>
</cfloop>
</cfloop>

Reply With Quote
  #2  
Old January 4th, 2005, 09:17 AM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,689 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 16 h 33 m 51 sec
Reputation Power: 53
Could you alter the format of the structure so that it uses the first letter of their last name as the key?

<cfset speakers = structNew()>
<cfset speakers.a.speaker1.name = "Daniel">
<cfset speakers.a.speaker1.pdf = "Daniel.pdf">
<cfset speakers.b.speaker1.name = "Tom">
<cfset speakers.b.speaker1.pdf = "Tom.pdf">
__________________
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 January 4th, 2005, 09:18 AM
bocmaxima's Avatar
bocmaxima bocmaxima is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Aug 2004
Location: Tucson, Sonora
Posts: 1,322 bocmaxima User rank is Sergeant (500 - 2000 Reputation Level)bocmaxima User rank is Sergeant (500 - 2000 Reputation Level)bocmaxima User rank is Sergeant (500 - 2000 Reputation Level)bocmaxima User rank is Sergeant (500 - 2000 Reputation Level)bocmaxima User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 17 h 46 m 5 sec
Reputation Power: 23
Send a message via AIM to bocmaxima
Have you tried StructFindValue?

Reply With Quote
  #4  
Old January 4th, 2005, 09:22 AM
DjPizat DjPizat is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Location: Mass
Posts: 26 DjPizat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 7 m 33 sec
Reputation Power: 0
Ooo,
I think i see where you're going with this one. It would be putting everyone into their last by a key. Yeah I could do that. How would i pull out people in .a? I'm guessing a structure function?

Reply With Quote
  #5  
Old January 4th, 2005, 09:36 AM
DjPizat DjPizat is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Location: Mass
Posts: 26 DjPizat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 7 m 33 sec
Reputation Power: 0
Ok i think i've figured it out.
Thanks for your help!

Reply With Quote
  #6  
Old January 4th, 2005, 03:20 PM
glively glively is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 17 glively User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 30 m 51 sec
Reputation Power: 0
IMHO this would be easier to accomplish with an array of structures.

<cfset variables.speakers = ArrayNew(1)>
<cfloop index="variables.i" from="1" to="#someLimit#">
<cfset variables.speakers[variables.i] = structNew()>
<cfset variables.speakers[variables.i].name = "Daniel">
<cfset variables.speakers[variables.i].pdf = "Daniel.pdf">
<cfset variables.speakers[variables.i].index = "a">
</cfloop>

Reply With Quote
  #7  
Old January 4th, 2005, 04:33 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,689 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 16 h 33 m 51 sec
Reputation Power: 53
It depends on what you're trying to do. If the goal is to be able to easily grab all the elements that have the same first letter in their last name, the solution you mention would actually be more complicated because you'd have to loop through the entire array to find all the elements with the same letter.

Reply With Quote
  #8  
Old January 4th, 2005, 04:38 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,689 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 16 h 33 m 51 sec
Reputation Power: 53
That said, if the goal IS to easily get all elements with the same first letter of the last name, using a structure of arrays would probably work even better. You wouldn't have to worry about naming each element uniquely within each letter.

<cfset speakers = structNew()>
<cfset speakers.a = arrayNew(1) />
<cfset speakers.a[1].name = "Daniel">
<cfset speakers.a[1].speaker1.pdf = "Daniel.pdf">
<cfset speakers.b = arrayNew(1) />
<cfset speakers.b[1].name = "Tom">
<cfset speakers.b[1].pdf = "Tom.pdf">

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > Structures: Finding Values


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 | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT