Get maximal text from a column

Hallo experts.
On a result page i have Dynamic text #dboartikel.Besonderheiten#.
This gets the values from a column with values like text1,text2,text3......
The question is how can i get on this page not all the values but only a number of it.
Like text1,text2 or if text1 not exists text2,text3
(if i want only 2 values).
regards
panos
LVL 2
PanosAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mr_NilCommented:
Take a look at the list functions.

ListGetAt()
ListFirst()
ListLast()

and so on.

If all you're going to be wanting is the first two items out of your list you can probably just use the above command to get them specificially. eg. #ListFirst(dboartikel.Besonderheiten)# and #ListGetAt(dboartikel.Besonderheiten,2)#

If you need a varying number combine a loop with the listGetAt() function to loop through your list pulling out the items you need.

Depending on your database you might be able to split your list up before you return it to coldfusion.  Also, you might want to look at restructuring your database so that you have an additional table which holds these lists in individual rows that are associated with your main table.
0
PanosAuthor Commented:
Hallo MR Nil.
Help me a bit more.
I use this code #ListFirst(dboartikel.Besonderheiten)#,#ListGetAt(dboartikel.Besonderheiten,2)#,#ListGetAt(dboartikel.Besonderheiten,3)#,#ListGetAt(dboartikel.Besonderheiten,4)#
.
If the column has less values f.ex. one value i have an error
 Invalid list index 2.
In function ListGetAt(list, index [, delimiters]), the value of index, 2, is not a valid as the first argument (this list has 1 elements). Valid indexes are in the range 1 through the number of elements in the list.
If the column has more than 4 i have again an error.
How can i fix it?
If i use the code for 4 values and in my column are more values than 4 how can i use [......] to symbolize that there are more values?
regards
panos

0
Mr_NilCommented:
ok - another list function that is available is ListLen.

Perhaps what you should do rather than directly get the list items is use the loop suggestion I had for you. Work out how many items you have in the list and adjust your loop accordingly.

Below is an untested piece of code that should do what you are after. I've put comments in the code so you can understand what each line is doing.

Hope that helps.
<!--- Set the maximum number items to display from the list --->
<cfset loopCount = 4 />
<!--- Count the number of items in the list --->
<cfset count_Items = ListLen(dboartikel.Besonderheiten) />
<!--- If we have less items than the maximum set the max to be the number of items --->
<cfif count_items LT loopCount><cfset loopCount = count_items /></cfif>
<!--- 
Loop through the list getting each item up to the maximum.
Also, put a comma after each item, unless its the last item.
--->
<cfloop from="1" to="#loopCount#" index="i">#ListGetAt(dboartikel.Besonderheiten,i)#<cfif i NEQ loopCount>,</cfif></cfloop>
<!--- If the number of items available is greater than the maximum display "..." --->
<cfif count_items GT loopCount>...</cfif>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PanosAuthor Commented:
thank you Mr Nil.
It was very very good!!!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.