Get maximal text from a column

Posted on 2008-02-01
Medium Priority
Last Modified: 2013-12-24
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).
Question by:Panos
  • 2
  • 2
LVL 10

Expert Comment

ID: 20798439
Take a look at the list functions.


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.

Author Comment

ID: 20803972
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?

LVL 10

Accepted Solution

Mr_Nil earned 2000 total points
ID: 20808506
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


Author Closing Comment

ID: 31427624
thank you Mr Nil.
It was very very good!!!!

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
This installment of Make It Better gives Media Temple customers the latest news, plugins, and tutorials to make their Grid shared hosting experience that much smoother.
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Free Data Recovery software is an advanced solution from Kernel Tools to recover data and files such as documents, emails, database, media and pictures, etc. It supports recovery from physical & logical drive after a hard disk crash, accidental/inte…
Suggested Courses

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question