How to make an unordered list from a database record?

Posted on 2008-11-13
Last Modified: 2013-12-24
I'm currently working on a real estate application and I need to populate information on a detail page with bulleted (unordered list) details about the house. The process works like this, user fills out an input form to insert the listing into the database, the database returns information on detail page.

The problem I'm having is- Being that the bulleted list will vary with each house I can't have a set number of feilds (bullet1 feild, bullet2 field and so on) so I was thinking of using a multiline text feild on the form page and inserting the bulleted list and hopeing to parse out each bullet (list item) by checking for a carrige return in the database record. I have no idea how to go about doing such a thing.

Recap, I need a way to auto popluate bulleted text from one record in a database (text with carriage returns. I hope this make sense.
Question by:jasch2244
    LVL 27

    Expert Comment

    this does make sense, and is easily done. all you need to do is treat your text as a cr/lf-delimited list and cfloop over it:

    <cfloop list="#myquery.textfield#" index="line" delimiters="#chr(13)&chr(10)#">
    <cfif len(trim(line))><li>#line</li></cfif>

    but you should consider modifying your data model to store each detail (your bulleted item) as a separate record in a house-details table, linked to the house via some house_id foreign key. this will be easier to manage and will make your db more normalized...

    LVL 1

    Author Comment

    Thank you for your quick response (wow). Oh please hang with me here...
    I am somewhat familiar with cfloop in that it loops over a list or query what have you. Is what you are proposing using a multiline text feild with content like [ this is a great house --line break--- the foyer is beautiful--line break] where at each line break the loop will create an li tag?

    Just not sure what #chr(13)&)&chr(10)# or <cfif len(trim(line))><li>#line</li> does.

    The data is contained in mysql in a varchar (255 characters).
    LVL 27

    Accepted Solution

    yes, that's what the code will do.
    assuming your db field contains text like:
    this is a great house[linebreak]
    the foyer is beautiful[linebreak]
    [something else about the house] is [great|wonderful|outstanding|spectacular|etc]

    the code will output the above as
    <li>this is a great house</li>
    <li>the foyer is beautiful</li>
    <li>[something else about the house] is [great|wonderful|outstanding|spectacular|etc]</li>

    a few explanations of the code:
    #chr(13)&chr(10)# is ascii code for CR [chr(13)] and LF [chr(10)] characters;
    #line# is the index assigned in the cfloop, and represents each ine in your text field as it is being looped over;
    <cfif len(trim(line))> checks that the length of current line is > 0. it is shorthand for <cfif len(trim(line)) gt 0>;


    LVL 1

    Author Closing Comment

    Thank you master! You have helped me in the past and I am forever greatful for your knowledge.

    Thank you, thank you

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    Title # Comments Views Activity
    Web server settings related to keepalive 1 31
    OSPF Routing Problems 9 49
    Wireshark 4 32
    PDF slideshow on a dynamic folder 12 18
    In order to have all security and back ups taken care of, WordPress users can sign up for services with WP Engine.
    Don’t let your business fall victim to the coming apocalypse – use our Survival Guide for the Fax Apocalypse to identify the risks and signs of zombie fax activities at your business.
    After creating this article (, I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now