Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cfif causing extra spaces in output

Status
Not open for further replies.

profwannabe

Programmer
Jan 6, 2001
53
US
I am trying to output bibliographic entries. The number of authors and their relative positions determines a variety of factors, such as "LastName, FirstName" versus "LastName, FirstName,", "FirstName LastName," or "and FirstName LastName". The same thing happens if the volume is edited and how many editors there are (e.g. ed. vs eds.).

To account for this I have a series of conditions within the loop that outputs the getAuthors query. The output is just fine, except that I get spaces resulting from the cfif statements. I have tried putting all the code on a single line (thinking that maybe by using separate lines in the code an extra space creeps in), but no luck. The code is below.
Code:
<cfloop query=&quot;getAuthors&quot;>
     <cfif LoopIndex GT 1>
	<cfif loopIndex LT getAuthors.RecordCount>
	     ,
	<cfelseif loopIndex EQ getAuthors.RecordCount>
	     and
	</cfif>
     </cfif>
     <cfif loopIndex IS 1>
	#Trim(getAuthors.AuthorLastName)#, #Trim(getAuthors.AuthorFirstName)#<cfif Trim(getAuthors.AuthorDesignation) NEQ &quot;&quot;> #Trim(getAuthors.AuthorDesignation)#</cfif>
     <cfelse>#Trim(getAuthors.AuthorFirstName)# #Trim(getAuthors.AuthorLastName)#<cfif Trim(getAuthors.AuthorDesignation) NEQ &quot;&quot;> #Trim(getAuthors.AuthorDesignation)#</cfif>
     </cfif>
     <cfif loopIndex EQ getAuthors.RecordCount>
	<cfif getVolumeInfo.Edited IS &quot;Yes&quot;>
	     <cfif getAuthors.RecordCount IS 1>
		, ed.
	     <cfelse>
		, eds.
	     </cfif>
	<cfelse>
	     .
	</cfif>
     </cfif>
     <cfset LoopIndex = IncrementValue(LoopIndex)>
</cfloop>
 
Try something like:

Trim(#getAuthors.AuthorLastName#)

That's what I do in my code.

Let me know if it works.

scripter73
Change Your Thinking, Change Your Life.
 
can you post up the output that this code is generating as an example of what it is we are trying to solve here.

tony
 
I am using the trim function, so that does not seem to be the issue.

Here is an example of the output:
Farber, H. S. and J. Gowa. 1996. &quot;Polities and Peace&quot;. In Debating the Democratic Peace: An International Security Reader. Brown, M. E. , S. M. Lynn-Jones and S. E. Miller , eds. Cambridge, MA : MIT Press, pp. 239-262.
Subjects: Democratic Peace

The commas are just hanging out there (the colon for the publisher has a space before and after by design). Hope this helps.
 
To clarify,

The commas that are &quot;floating&quot; are the ones between authors' names (the one between LastName, FirstName is fine, thanks perhaps to the Trim function) and the one preceeding eds. (the code is for &quot;, eds.&quot;). Oddly enough, for this chunk of code:

<cfif loopIndex LT getAuthors.RecordCount>
,
<cfelseif loopIndex EQ getAuthors.RecordCount>
and
</cfif>
.. there seems to be an extra space preceding the comma but not the and (of course, this may just be a function of there needing to be a single space befor the &quot;and&quot; and HTML not recognizing more than one space, so the effect may just be hidden).
Hope that makes sense.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top