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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Show only 100 characters of field

Status
Not open for further replies.

rmz8

Programmer
Aug 24, 2000
210
US
I want a search to return results formatted to show the first 100 characters of field 'Body.' I can use the LEN function, but I fear that in dealing with a field with contents of thousands upon thousands of characters, this process would slow down the site's performance. Is there any other way to limit the data shown to only 100 characters?
 
Hi!

Use the LEFT function to return only the 100 first characters...

ex:
<CFSET cutString = LEFT(body, 100)>
<CFOUTPUT>
#cutString#
</CFOUTPUT>

you will only have the 100 first characters...
Chris
 
Thanks a lot Chris!

Ryan ;-]
 
What if I have a collection of 30 records, each of which I want to create a different summary for using the contents of 'Body'? Here is what I have:

<CFQUERY NAME=&quot;Search&quot; DATASOURCE=&quot;myjobcoach&quot; BLOCKFACTOR=&quot;100&quot;>SELECT ID, Headline, Body FROM Content_Database WHERE Category1 LIKE '%#URL.Category1#%' AND Category2 LIKE '%#URL.Category2#%' ORDER BY Headline ASC</CFQUERY>
<CFSET Summary = LEFT(Search.Body, 255)>

<CFTABLE QUERY=&quot;Search&quot; COLHEADERS HTMLTABLE><CFCOL TEXT=&quot;<a href='display_article.cfm?ID=#Search.ID#&Client_Name=#Design.Client_Name#'><b>#Search.Headline#</b></a><br><i>#Summary#</i>
<br><br>&quot;></CFTABLE>

When I refer to 'Summary' above, it shows the same one for all of the results, since CFSET only built one summary, from the first record returned by the QUERY. How can I have it build seperate summaries and then refer to it in the results? [sig]<p>Ryan ;-]<br>[/sig]
 
Hi Ryan,

I'm still a CF Newbie, but try this:

<CFQUERY NAME=&quot;Search&quot; DATASOURCE=&quot;myjobcoach&quot; BLOCKFACTOR=&quot;100&quot;>
SELECT ID, Headline, Body
FROM Content_Database
WHERE Category1 LIKE '%#URL.Category1#%' AND Category2 LIKE '%#URL.Category2#%'
ORDER BY Headline ASC
</CFQUERY>


<CFTABLE QUERY=&quot;Search&quot; COLHEADERS HTMLTABLE>
<CFSET Summary = #LEFT(Search.Body, 255)#>
<CFCOL TEXT=&quot;<a href='display_article.cfm?ID=#Search.ID#&Client_Name=#Design.Client_Name#'><b>#Search.Headline#</b></a><br><i>#Summary#</i><br><br>&quot;></CFTABLE>

----------------
or
----------------

<CFQUERY NAME=&quot;Search&quot; DATASOURCE=&quot;myjobcoach&quot; BLOCKFACTOR=&quot;100&quot;>
SELECT ID, Headline, Body
FROM Content_Database
WHERE Category1 LIKE '%#URL.Category1#%' AND Category2 LIKE '%#URL.Category2#%'
ORDER BY Headline ASC
</CFQUERY>


<CFTABLE QUERY=&quot;Search&quot; COLHEADERS HTMLTABLE>
<CFCOL TEXT=&quot;<a href='display_article.cfm?ID=#Search.ID#&Client_Name=#Design.Client_Name#'><b>#Search.Headline#</b></a><br><i>#LEFT(Search.Body, 255)#</i><br><br>&quot;></CFTABLE>

But I think this way might take up more of the server resources.

Hope this was of some help,
NeoTurtle [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top