Professional Web Applications Themes

Showing the first sentence of a paragraph - Macromedia ColdFusion

OK, I have the code to show the first sentence of a particular field - but it isn't working quite right - sometimes it shows two sentences, sometimes it cuts off in the middle of a sentence. When I looked at it again, I realized that the way I have the code, it's only looking at the very first instance of that particular field, and than using that number for all the fields. I think it needs a loop or something so that it knows to look for the first sentence in each separate instance of the description field - ...

  1. #1

    Default Showing the first sentence of a paragraph

    OK, I have the code to show the first sentence of a particular field - but it
    isn't working quite right - sometimes it shows two sentences, sometimes it cuts
    off in the middle of a sentence. When I looked at it again, I realized that the
    way I have the code, it's only looking at the very first instance of that
    particular field, and than using that number for all the fields. I think it
    needs a loop or something so that it knows to look for the first sentence in
    each separate instance of the description field - but I'm not sure how to do
    that.

    Here's the original code:

    <cfquery name="get_links" datasource="links_1" dbtype="ODBC">
    SELECT links.link_id, links.title, links.link, links.description,
    links.url_home, links.icon, links.url_tutorial,
    subjecttype.subject_name, subject.link_id, subjecttype.subjecttype_id,
    subject.subjecttype_id
    FROM links, subjecttype, subject
    WHERE links.link_id = subject.link_id
    AND subjecttype.subjecttype_id = subject.subjecttype_id
    AND (subject.subjecttype_id = #url.subjecttype_id#)
    ORDER BY title
    </cfquery>

    <cfset variables.firstsentence = Find( ".", #get_links.description#)>

    and the whole code for the output:

    <cfoutput query="get_links"><tr>
    <td align="right" valign="top">
    <img src="../images/#icon#.gif" alt="database icon" width="50"
    height="50" hspace="5" align="left" /></td>
    <td align="left" valign="top">
    <cfif url_home IS "">
    <cfif icon IS NOT "free">
    <span class="bold">#TRIM(title)#</span><br />
    <a href="#link#" title="#TRIM(title)# - inside the
    library">inside the library</a><br />
    <cfelse>
    <a href="#link#" title="#TRIM(title)#">#TRIM(title)#</a><br />
    </cfif>
    <cfelse>
    <span class="bold">#TRIM(title)#</span><br />
    <a href="#link#" title="#TRIM(title)# - inside the library">inside the
    library</a> |
    <a href="#url_home#" title="#TRIM(title)# - home
    access">home access</a> <br />
    </cfif>
    #Left(get_links.description, variables.firstsentence)#(<a
    href="database_spotlight.cfm?link_id=#link_id#">fi nd out more...</a> ) <cfif
    url_tutorial IS NOT "">
    <br />
    <a href="../../pdf/#url_tutorial#">See a Ten Minute Tutorial for this
    database</a> (<span class="red">*</span> tutorial requires <a
    href="http://www.adobe.com/products/acrobat/readstep2.html">Adobe Acrobat
    Reader</a>)
    </cfif></td>
    </tr></cfoutput>

    You can see this in action at
    [url]http://www.richland.lib.sc.us/sample/linkstest.cfm?subjecttype_id=23[/url]. It looks
    at the first instance of the description field (for the Africa: An Encyclopedia
    for Students database, finds that period is at space 252 - and then uses 252
    for all the other instances of the description field.

    Micheller Guest

  2. #2

    Default Re: Showing the first sentence of a paragraph

    Whoops - forgot to add - Thanks for any suggestions or asisstance. I really appreciate it.
    Micheller Guest

  3. #3

    Default Re: Showing the first sentence of a paragraph

    Hi Michelle (long time no talkee),

    Let the database do this.

    Simplified,

    SELECT substring(links.description,1,charindex('.',links. description)) as
    short_desc ....

    This is T-SQL but you can probably translate to other DB flavors.

    HTH,

    philh Guest

  4. #4

    Default Re: Showing the first sentence of a paragraph

    Hi Phil - my old saviour ';-)

    I think I understand what you mean, but I'm using Access which isn't happy
    about it.

    I tried

    <cfquery name="get_links" datasource="links_1" dbtype="ODBC">
    SELECT links.link_id, links.title, links.link,
    substring(links.description,1,charindex('.',links. description)) as short_desc,
    links.url_home, links.icon, links.url_tutorial,
    subjecttype.subject_name, subject.link_id, subjecttype.subjecttype_id,
    subject.subjecttype_id
    FROM links, subjecttype, subject
    WHERE links.link_id = subject.link_id
    AND subjecttype.subjecttype_id = subject.subjecttype_id
    AND (subject.subjecttype_id = #url.subjecttype_id#)
    ORDER BY title
    </cfquery>

    and got

    error Executing Database Query.
    [Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft
    Access Driver] Undefined function 'substring' in expression.

    I'm trying to look around and find some information on Access SQL so I can
    figure out how it should be phrased - or should I have put it into a separate
    query?

    Thanks - I'm still just as clueless as ever..

    Micheller Guest

  5. #5

    Default Re: Showing the first sentence of a paragraph

    You would have to use the equivalent Access functions....

    Something like this, perhaps?

    Left(links.description,InStr('.',links.description ))

    paross1 Guest

  6. #6

    Default Re: Showing the first sentence of a paragraph

    Just use:

    <cfset variables.firstsentence = ListFirst(get_links.description,".")>

    OldCFer Guest

  7. #7

    Default Re: Showing the first sentence of a paragraph

    Thanks for all the suggestions! I really appreciate it.

    I tried using Left(links.description,InStr('.',links.description )) and that
    didn't give me error messages, but the output didn't show any descriptions at
    all.

    I also tried <cfset variables.firstsentence =
    ListFirst(get_links.description,".")> but that gives me a different version of
    my original problem. Then, the first sentence of the first instance of the
    description variable had 254 characters, so every other instance of the
    variable showed 254 characters even though the first sentences were of varying
    length. Now it's just repeating the first sentence of the first instance of
    the variable over and over, instead of giving the first sentence for each
    instance of the variable:

    [url]http://www.richland.lib.sc.us/sample/linkstest.cfm?subjecttype_id=23[/url]

    Thanks again.

    Micheller Guest

  8. #8

    Default Re: Showing the first sentence of a paragraph

    Oops, sorry, I had my Access InStr syntax wrong...

    Left(links.description,InStr(links.description, '.'))

    Phil

    paross1 Guest

  9. #9

    Default Re: Showing the first sentence of a paragraph

    You problem is you're finding the first sentence for the first record then using
    that for all records. All you have to do is move that into your <cfoutput>.
    like this:

    <cfoutput query="get_links">
    <cfset variables.firstsentence = ListFirst(description,".")>

    not

    <cfset variables.firstsentence = ListFirst(get_links.description,".")>
    <cfoutput query="get_links"><

    OldCFer Guest

Similar Threads

  1. #39264 [Opn->Bgs]: Problem with IF sentence
    By derick@php.net in forum PHP Bugs
    Replies: 0
    Last Post: October 26th, 11:52 AM
  2. #39264 [NEW]: Problem with IF sentence
    By hipolitoalvarez at yahoo dot com dot ar in forum PHP Bugs
    Replies: 0
    Last Post: October 26th, 11:46 AM
  3. Sentence Drag
    By Flash_Neophyte webforumsuser@macromedia.com in forum Macromedia Flash Actionscript
    Replies: 0
    Last Post: February 6th, 05:54 PM
  4. To count Words of a Sentence
    By Fredg in forum Microsoft Access
    Replies: 5
    Last Post: July 29th, 01:16 AM
  5. Sentence /paragraph spacing
    By pyrolabs webforumsuser@macromedia.com in forum Macromedia Dreamweaver
    Replies: 1
    Last Post: July 8th, 08:52 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139