don't print print [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => [ref] => [htmlstate] => on_nl2br [postusername] => mxstu [ip] => webforumsuser@m [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 5 [islastshown] => [isfirstshown] => [attachments] => [allattachments] => ) --> #eJournalList.jNotes2#
[allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => [ref] => [htmlstate] => on_nl2br [postusername] => jdeline [ip] => jdeline@deline. [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 12 [islastshown] => [isfirstshown] => [attachments] => [allattachments] => ) --> Empty Fields - Coldfusion - Getting Started

Empty Fields - Coldfusion - Getting Started

I am new to CF. I am trying to figure out how to remove blank lines from my output when there are no values for a particular field in the database. Do I need to fill the field with a null value or something? Thanks....

  1. #1

    Default Empty Fields

    I am new to CF. I am trying to figure out how to remove blank lines from my
    output when there are no values for a particular field in the database. Do I
    need to fill the field with a null value or something? Thanks.

    HMOKeefe Guest

  2. #2

    Default Re: Empty Fields

    You can do something like the code below. But make sure the line is truly
    blank - that it does not contain any unprintable characters like ASCII 10 or 13.



    <CFIF myQuery.fieldName IS "">
    Don't print
    <CFELSE>
    Do print
    </CFIF>

    jdeline Guest

  3. #3

    Default Re: Empty Fields

    Where should I put this code, after the <cfquery name>, within the <cfoutput>
    statement or after the statement? Wherever I put it I can't seem to keep the
    "Don't print" and "Do print" from actually printing...and so far the statement
    doesn't seem to remove the blank line. This is what I have so far:

    <cfoutput query="eJournalList">
    <p><span class="eJournalTitle"><a href="#eJournalList.jURL#"
    target="_blank">#eJournalList.jName#
    </a></span> <br />
    #eJournalList.jAbbrev#<br />
    #eJournalList.jVolumeStart#- #eJournalList.jVolumeEnd#
    (#eJournalList.jDateStart# - #eJournalList.jDateEnd# )<br />
    #eJournalList.jNotes1#<br />
    #eJournalList.jNotes2#<br />
    #eJournalList.jUsername#</p>
    </cfoutput>
    <cfif #eJournalList.jNotes2# IS "">
    Don't print
    <cfelse>
    Do print
    </cfif>

    HMOKeefe Guest

  4. #4

    Default Re: Empty Fields

    Jdeline is of course right. You could decide to go for zero tolerance with

    <CFIF Len(myQuery.fieldName) EQ 0>
    Don't print
    <CFELSE>
    Do print
    </CFIF>

    BKBK Guest

  5. #5

    Default Re: Empty Fields

    You can use the TRIM() function to get rid of the whitespace characters (like
    CR, LF, TAB, etc) before testing the value.

    <!--- sample line with all whitespace characters --->
    <CFSET myLine = chr(10) & chr(13) & chr(11)>
    <CFIF TRIM(myLine) EQ "">
    don't print
    <CFELSE>
    print
    </CFIF>

    mxstu Guest

  6. #6

    Default Re: Empty Fields

    Move the </CFOUTPUT> after the </CFIF>. What that does is include the <CFIF><CFELSE></CFIF> in the
    <cfoutput query="eJournalList"> loop.

    Actually, I like BKBK's suggestion better than mine.
    jdeline Guest

  7. #7

    Default Re: Empty Fields

    > You could decide to go for zero tolerance with
    ><CFIF Len(myQuery.fieldName) EQ 0>
    Although I do prefer using LEN(), you still need to TRIM() the values to
    eliminate the whitespace padding (CR, LF, TAB, etc).

    mxstu Guest

  8. #8

    Default Re: Empty Fields

    As you suggested, .i tried this. Here is the code:

    <body>
    <p><a href="../Journals/eJournals_process.cfm?letter=A">A</a> | <a
    href="../Journals/eJournals_process.cfm?letter=B">B</a> | <a
    href="../Journals/eJournals_process.cfm?letter=C">C</a> | <a
    href="../Journals/eJournals_process.cfm?letter=D">D</a> | <a
    href="../Journals/eJournals_process.cfm?letter=E">E</a> | <a
    href="../Journals/eJournals_process.cfm?letter=F">F</a> | <a
    href="../Journals/eJournals_process.cfm?letter=G">G</a> | <a
    href="../Journals/eJournals_process.cfm?letter=H">H</a> | <a
    href="../Journals/eJournals_process.cfm?letter=I">I</a> | <a
    href="../Journals/eJournals_process.cfm?letter=J">J</a> | K | L | <a
    href="../Journals/eJournals_process.cfm?letter=M">M</a> | <a
    href="../Journals/eJournals_process.cfm?letter=N">N</a> | <a
    href="../Journals/eJournals_process.cfm?letter=O">O</a> | <a
    href="../Journals/eJournals_process.cfm?letter=P">P</a> | Q | R | <a
    href="../Journals/eJournals_process.cfm?letter=S">S</a> | <a
    href="../Journals/eJournals_process.cfm?letter=T">T</a> | U | V | W | X | Y | Z
    |</p><cfoutput query="eJournalList">
    <p><span class="eJournalTitle"><a href="#eJournalList.jURL#"
    target="_blank">#eJournalList.jName#</a></span><br />
    #eJournalList.jAbbrev#<br />
    #eJournalList.jVolumeStart#- #eJournalList.jVolumeEnd#
    (#eJournalList.jDateStart# - #eJournalList.jDateEnd# )<br />
    #eJournalList.jNotes1#<br />
    #eJournalList.jNotes2#<br />
    #eJournalList.jUsername#</p>
    <cfif eJournalList.jNotes2 IS "">
    Don't print
    <cfelse>
    Do print
    </cfif>
    </cfoutput>
    </body>
    </html>

    and here is the output:

    A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T
    | U | V | W | X | Y | Z |

    Oligonucleotides
    Oligonucleotides
    10(4)- (Aug 2000 - )
    available online from the publisher
    continues Antisense and Nucleic Acid Drug Development

    Do print

    Oral Diseases
    Oral Dis
    7- (2001 - )
    available online from the publisher

    Don't print

    Oral Microbiology and Immunology
    Oral Microbiol Immunol
    14- (1999 - )
    available online from the publisher


    Don't print

    Oral Surgery, Oral Medicine, Oral Pathology, Oral Radiology and Endodontics
    Oral Surg Oral Med Oral Pathol Oral Radiol Endod
    87- (1999 - )
    available online from the publisher

    <------------- (((((i am trying to get rid of this space))))
    username and password: FORSYTH

    Don't print

    Orthodontics and Craniofacial Research
    Orthod Craniofac Res
    7- (2004 - )
    available online from the publisher


    Don't print <<---------- why do these show up?>>

    HMOKeefe Guest

  9. #9

    Default Re: Empty Fields

    The "Do print" and "Don't print" in my earlier post were placeholders to show the logic flow in the CFIF block. Take them out of your code.
    jdeline Guest

  10. #10

    Default Re: Empty Fields

    I am clearly missing something here. If I take out the Don't print and Do
    print, how does the IF ELSE statement know what to do? Is it implicit from the
    IF statement that you either PRINT or DON'T PRINT? I took it out and I still
    get blank lines when the jNotes2 field is empty

    HMOKeefe Guest

  11. #11

    Default Re: Empty Fields

    This is an example of the ouput resulting from the empty jNotes2 field in my
    database:

    Oral Surgery, Oral Medicine, Oral Pathology, Oral Radiology and Endodontics
    Oral Surg Oral Med Oral Pathol Oral Radiol Endod
    87- (1999 - )
    available online from the publisher

    <------------- ((((this is the blank line created by empty jNotes2
    field)))
    username and password: FORSYTH

    HMOKeefe Guest

  12. #12

    Default Re: Empty Fields

    The <CFIF> statement I posted used "Do Print" and "Don't Print" as
    placeholders. That means that the code you want to execute if the <CFIF>
    condition is TRUE replades the "Do Print" text. The code you want to execute
    if the <CFIF> condition is FALSE replaces the "Don't Print" text. So if you do
    not want to print eJournalList.jNotes2 if it is not present, your <CFIF> would
    look like the code below.


    <!--- display the eJournalList.notes2 if it is present --->
    <cfif eJournalList.jNotes2 IS NOT "">
    #eJournalList.jNotes2#<br />
    </cfif>

    jdeline Guest

  13. #13

    Default Re: Empty Fields

    Thank you and now that I understand how this conditional statement works, I
    learned that I had to replace the previous print statements with this
    conditional statement to remove the blank line my final correct code reads:

    <cfoutput query="eJournalList">
    <p><span class="eJournalTitle"><a href="#eJournalList.jURL#"
    target="_blank">#eJournalList.jName#</a></span><br />
    #eJournalList.jAbbrev#<br />
    #eJournalList.jVolumeStart#- #eJournalList.jVolumeEnd#
    (#eJournalList.jDateStart# - #eJournalList.jDateEnd# )<br />
    #eJournalList.jNotes1#<br />
    <cfif eJournalList.jNotes2 IS NOT "">
    #eJournalList.jNotes2#
    <cfelse>
    #eJournalList.jUsername#
    </cfif>
    </cfoutput>

    HMOKeefe Guest

Similar Threads

  1. Check Empty form fields
    By wavesurfer in forum Macromedia Exchange Dreamweaver Extensions
    Replies: 0
    Last Post: August 19th, 10:05 AM
  2. Dealing with empty fields from database query
    By Ian50 in forum Dreamweaver AppDev
    Replies: 0
    Last Post: February 22nd, 06:04 AM
  3. Replies: 2
    Last Post: August 12th, 02:52 PM
  4. Replies: 1
    Last Post: March 4th, 07:46 PM
  5. Omitting form fields if empty
    By JDJones in forum PHP Development
    Replies: 1
    Last Post: September 8th, 06:20 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
  •