 | cfquery & paragraph breaks |  |
|
john barrett
| Joined: 04 Nov 2005 |
| Posts: 41 |
| Location: Hawaii |
|
 |
Posted: Thu Dec 06, 2007 3:42 am |
|
 |
 |
 |
 |
I am display articles from a database, but I need the text formated with <p>...</p>.
That is before each line a <p> tag,and after each line a <p>. There must be a way to do this within your cfquery, right?
An example of the page (the static html version) is here:
http://www.nutritionatc.hawaii.edu/HO/2007/381.htm
But the ColdFusion version I can't seem to format the same way(I am using the same CSS) but in the ColdFusion version I do not have the <p></p> tags before and after each line, which is why the format is not the same way.
I don't think that there is a way to add html inside the database, so there must be another way??
The query that I am using to display the text is:
<cfquery name="get_article" datasource=" my_datasource" >
select article_title, article_text from articles where article_id = '#article_id# '
</cfquery>
</div>
<cfoutput>
<div align="center" ><strong> #get_article. article_title# </strong> </div>
</cfoutput>< /p>
<p> </p>
<p><cfoutput> <p>#get_article. article_text# </p>
</cfoutput> |
Thanks for any help:)
John
|
|
|
 |
 | |  |
|
Jason101
Forum Regular
| Joined: 14 Mar 2006 |
| Posts: 547 |
| Location: Harrisburg, PA |
|
 |
Posted: Thu Dec 06, 2007 1:44 pm |
|
 |
 |
 |
 |
Unless you can specifically tell where there is a break in the text you can do it. For example, say in your database the text is formatted as
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed vel sapien in dui pulvinar tincidunt. Etiam pede ligula, rutrum id, luctus at, feugiat at, est. Nam turpis purus, nonummy ut, placerat id, euismod sit amet, eros. Curabitur blandit.
Sed vel arcu vitae leo nonummy viverra. Integer vel erat. Suspendisse quis felis. Maecenas vel quam eu est rutrum interdum. Sed in lacus eget diam suscipit ultricies. In consequat ligula nec pede. Nulla purus. Praesent euismod ullamcorper lectus.
|
There are obviously no p tags in the above, but there are still breaks. What you can do, is search for a line feed or carriage return, and then insert your tags accordingly. You can try either one of these:
For a line feed:
ReplaceNoCase(get_article.article_text, chr(10),'</p><p>', 'All')
|
For a carriage return:
ReplaceNoCase(get_article.article_text, chr(10),'</p><p>', 'All')
|
Decimal Codes:
- Line Feed
- Carriage Return
|
You may get some empty p tags depending on the amount of line feeds, or carriage returns, but you can always use RegEx to remove them.
Copy and paste this code into a new CFM file and run it for an example:
<cfsavecontent variable="DBoutput">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Duis dapibus dolor aliquet libero. Pellentesque nec arcu. Vivamus tincidunt sem eu urna. Curabitur dapibus. Nullam id mauris. Quisque pulvinar, sem ut pulvinar condimentum, lacus odio venenatis dolor, at ullamcorper velit mi vitae nulla. Nam eget sem et quam mattis accumsan. Vivamus nisl leo, pellentesque quis, gravida et, porta quis, nisl. Donec velit. Nullam eu sem. Aliquam erat volutpat. Cras lacinia, nibh a mollis malesuada, sapien dolor pellentesque tortor, eu auctor est metus at est. Quisque orci massa, volutpat nec, imperdiet eu, elementum a, odio. Donec laoreet metus ac turpis.
Morbi et sapien. Donec est. Phasellus gravida lorem sed urna. Suspendisse at orci. Sed non tortor quis augue congue ornare. Ut nec nulla. In lectus. Mauris orci metus, cursus vitae, rhoncus nec, viverra vel, neque. Morbi mollis volutpat quam. Vestibulum et nisi ac ipsum aliquet accumsan. Aenean auctor congue magna. Nunc tempus. Sed cursus velit nec nulla. Curabitur massa lectus, lacinia id, fermentum at, consequat at, quam. Quisque mollis mi eu ligula. Nulla facilisi. Praesent ultrices magna et lacus.</cfsavecontent>
<cfset HTMLDBOutput = ReplaceNoCase(DBoutput, chr(10),'</p><p>',"All")>
<cfoutput>
<p>#HTMLDBOutput#</p>
</cfoutput>
<strong>CODE VIEW:</strong><br/>
<cfdump var="#HTMLDBOutput#">
|
I would highly advice you just store HTML in your DB to begin with. It will make things much cleaner:P
Hope this helps. 
|
|
|
 |
 | |  |
|
john barrett
| Joined: 04 Nov 2005 |
| Posts: 41 |
| Location: Hawaii |
|
 |
Posted: Fri Dec 07, 2007 8:31 am |
|
 |
 |
 |
 |
Hi Jason,
Thank you so much for helping me this!
I just added the html to the database, I did not know you could do that to begin with.
I printed this out, as I want to learn it.
Thanks again for all your help,
John 
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
All times are GMT
Page 1 of 1
|
|
|
|
|