|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Displaying commas and hyphens
This is going to be very basic...
I want to display records with varying results, in this case 'Practice1', 'Practice2', …’Practice6’. However, not all members have 6 practices. I want each ‘Practice’ record separated by a comma, without out displaying unnecessary commas. The following is definitely not the way to go. Any suggestions? Thanks in advance. <ul> <cfoutput query="GetMembers"> <tr> <td height="20" colspan="5" align="left" class="style2"> <li><A HREF="LawDetailsForm.cfm?UserID=#URLEncodedFormat(Trim(UserID))#">#FName# #MI# #LName#</a> - #Status#</li></td> </tr> <tr> <td height="20" colspan="5" align="left" class="style4">#Practice1#, #Practice2#, #Practice3#, #Practice4#, #Practice5#, #Practice6#</td> </tr> </cfoutput> </ul> |
|
#2
|
|||
|
|||
|
Hi Steve try this
Try this <ul> <cfoutput query="GetMembers"> <cfset PracticeList = ''> <cfloop from="1" to="6" index="i"> <cfif len(trim(GetMembers['Practice'&i]))> <cfset PracticeList = listappend(PracticeList,GetMembers['Practice'&i])> </cfif> </cfloop> <tr> <td height="20" colspan="5" align="left" class="style2"> <li><A HREF="LawDetailsForm.cfm?UserID=#URLEncodedFormat(Trim(UserID))#">#FName# #MI# #LName#</a> - #Status#</li></td> </tr> <tr><td height="20" colspan="5" align="left" class="style4">#PracticeList# </td></tr> </cfoutput> </ul> |
|
#3
|
||||
|
||||
|
i prefer this, it's a lot simpler --
<td height="20" colspan="5" align="left" class="style4"> <cfif len(Practice1)>#Practice1#, </cfif> <cfif len(Practice2)>#Practice2#, </cfif> <cfif len(Practice3)>#Practice3#, </cfif> <cfif len(Practice4)>#Practice4#, </cfif> <cfif len(Practice5)>#Practice5#, </cfif> <cfif len(Practice6)>#Practice6#</cfif></td></tr> |
|
#4
|
||||
|
||||
|
Quote:
I like this solution but I would move the commas around so that the first element's comma is on the second line, etc. Because the first element being present is no guarantee that a second will be, so unless you get all 6 elements you will have a stray comma at the end. wdn2k |
|
#5
|
||||
|
||||
|
good catch, wdn2k, i can't believe i did that!!
|
|
#6
|
||||
|
||||
|
uh oh, hold on a sec
if the first element is missing, and any other is present, you'll get that leading comma but if the app fills in the 6 slots from left to tight, it may not be a concern ![]() |
|
#7
|
|||
|
|||
|
<cfset PracticeList = ''>
<cfloop from="1" to="6" index="i"> <cfif len(trim(GetMembers['Practice'&i]))> <cfset PracticeList = listappend(PracticeList,GetMembers['Practice'&i])> </cfif> </cfloop> ![]() |
|
#8
|
|||
|
|||
|
Thank you for all of the help. I have received much better advise from this forum than anywhere else.
Currently I have opted for r937's idea. My only concern is that there is always a trailing comma, even after the last entry. I tried stpaz's latest and received the following error: Complex object types cannot be converted to simple values. The expression has requested a variable or an intermediate expression result as a simple value, however, the result cannot be converted to a simple value. Simple values are strings, numbers, boolean values, and date/time values. Queries, arrays, and COM objects are examples of complex values. The most likely cause of the error is that you are trying to use a complex value as a simple one. For example, you might be trying to use a query variable in a <CFIF> tag. This was possible in ColdFusion 2.0 but creates an error in later versions. The error occurred in C:\Inetpub\wwwroot\Lawyer\FirmDetailsForm.cfm: line 161 159 : <cfset PracticeList = ''> 160 : <cfloop from="1" to="6" index="i"> 161 : <cfif len(trim(GetMembers['Practice'&i]))> 162 : <cfset PracticeList = listappend(PracticeList,GetMembers['Practice'&i])> 163 : </cfif> Thanks again for the help. I've been away for two years and am very rusty. |
|
#9
|
||||
|
||||
|
Quote:
If it were me I'd make sure the slots were filled in the order I needed. ![]() |
|
#10
|
|||
|
|||
|
Quote:
Done that. However, there is still the trailing comma after the last slot, regardless of which one: Practice1, Practice2, Practice3, Practice4, Practice5, Practice6, BTW, thanks to everyone for your help and patience... |
|
#11
|
||||
|
||||
|
Quote:
My post above solves that. Place the comma that would follow element1 just before element2, etc. <cfif len(Practice1)>#Practice1# </cfif> <cfif len(Practice2)>, #Practice2# </cfif> <cfif len(Practice3)>, #Practice3# </cfif> etc. wdn2k |
|
#12
|
||||
|
||||
|
Quote:
![]() |
|
#13
|
||||
|
||||
|
Quote:
If it were me I'd make sure the slots were filled in the order I needed.... |
|
#14
|
|||
|
|||
|
Quote:
You guys are the best! Thanks. Now that I see what you did, I'm embarassed that I didn't think of it. Thanks again... |