How to make an unordered list from a database record?

Posted on 2008-11-13
Medium Priority
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
  • 2
  • 2
LVL 27

Expert Comment

ID: 22956958
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...


Author Comment

ID: 22957008
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

azadisaryev earned 2000 total points
ID: 22957028
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>;



Author Closing Comment

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

Thank you, thank you

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

Unable to change the program that handles the scan event from a network attached Canon/Brother printer/scanner. This means you'll always have to choose which program handles this action, e.g. ControlCenter4 (in the case of a Brother).
LinkedIn blogging is great for networking, building up an audience, and expanding your influence as well. However, if you want to achieve these results, you need to work really hard to make your post worth liking and sharing. Here are 4 tips that ca…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

807 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