Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

output of query gives unwanted whitespace

New Here ,
Jul 04, 2008 Jul 04, 2008
Hi

A client asked to create a small application in CF. I have no experience with cf and now I have a problem.

I'm querying a database and I want to put the results of the query on screen. Inititally I used the cfoutput tag to output the entire query to the screen, but it gives me a white space between the different records. I don't want that since it's html code that I'm putting on the screen.
I also tried looping through the query myself with cfloop and then use the output tag

How can I prevent the white space between the different records ?

thx !
TOPICS
Getting started
676
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 04, 2008 Jul 04, 2008
Your post does not have enough detail. How does your data appear now, and how would you like it to appear?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 04, 2008 Jul 04, 2008
quote:

Originally posted by: Dan Bracuk
Your post does not have enough detail. How does your data appear now, and how would you like it to appear?


It gives me part1 part2 part3 and what I want is part1part2part3 , so without the space in between them.

The problem is that if a html-tag is seperated over 2 parts that it will be outputed with a space and so it won't be interpretated as a HTML-tag.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 04, 2008 Jul 04, 2008
can you give more details on how you save your data to the database? anyway, have you tried trimming the space?

<cfoutput query="your_query">
#Trim(your_field)#
</cfoutput>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 07, 2008 Jul 07, 2008
Ok, some extra info:

I'm using (richttext) cftextarea to gather a html-structured text. That text has to be written to a database. So I chunk the text up in parts of 300 characters and write those parts of 300 chars to the database. I use this code:

<cfset myText = contentOfTextarea... >

<cfloop condition="len(myText) GT 0">
<cfset counter=counter+1>
<cfset myString=left(myText,300)>
<cfif len(myText) GT 300>
<cfset myText=mid(myText,301,len(myText)-300)>
<cfelse>
<cfset myText="">
</cfif>
<cfquery name="qryPasInhoudAan" datasource="ecolife">
insert into database...
</cfquery>
</cfloop>

Later, when I try to display the text - that was written or edited with the cftextarea - I use the following code:

<cfquery name="pagina_inhoud" datasource="ecolife">
SELECT inhHtml FROM pov_inhoud where inhPaginaId=#thisPage#
</cfquery>

<cfloop
query = "pagina_inhoud"
startRow = "1"
endRow = "#pagina_inhoud.RecordCount#">
<cfoutput>#pagina_inhoud.inhHtml#</cfoutput>
</cfloop>

So the problem remains that between every part of (300 chars of ) html cf puts a spaces which makes some html-tages not work because there is a space in them. I get things like </ p> in my resultpage.

I ' ve also tried trimming but the white space does not come from the database so trimming doesn't helps me out.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 07, 2008 Jul 07, 2008
Let me check if I get you right. So, you are actually trying to save your HTML by parts into different rows in your db. After that, you extract all the rows and use the cfloop to display all the rows, which will sum the parts of your HTML. You should consider 2 things:

1.) Basing on your query pagina_inhoud, I don't see any ORDER BY clause. I think when your query doesn't have an ORDER BY, sometimes row 2 can come first before row 1. In this case, there is a possibility that your HTML might be displayed incorrectly. I think you should consider the ordering/sorting of your rows when your data is returned from db. I mean, you should put another field which will determine the order/sort of the returned rows so as not to misplace some parts of your HTML when outputting the data.

2.) Another thing is the way you output your data. The problem is when there are spaces before and after your <cfoutput> tag as shown below:

[spaces here] <cfoutput>#pagina_inhoud.inhHtml#</cfoutput> [spaces here]

The format above can also cause your HTML code to have spaces in between. In order to avoid this, make sure there are no spaces on those part of your code. To do this, use cfsetting tag in your output as shown below.

<cfsetting enableCFoutputOnly = "yes"> <!--- this will block any HTML output(including spaces) after this tag and those that are outside the cfoutput tags --->
<cfloop
query = "pagina_inhoud"
startRow = "1"
endRow = "#pagina_inhoud.RecordCount#">
<cfoutput>#pagina_inhoud.inhHtml#</cfoutput>
</cfloop>
<cfsetting enableCFoutputOnly = "no"> <!--- change back to "no" to make sure that HTML outputs after this tag are displayed --->
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 08, 2008 Jul 08, 2008
LATEST
Problem solved! It was indeed a problem of a white space (tab) between the beginning of the loop and the output tag.
Thanks a lot dongzky (& Dan Bracuk)!


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 04, 2008 Jul 04, 2008
What html tags are you talking about? Unless your data has trailing spaces, this will work.

<cfoutput query="your_query">
#your_field#
</cfoutput>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources