Skip to main content
Participant
February 10, 2010
Answered

Simple but I'm a newbie!!

  • February 10, 2010
  • 1 reply
  • 581 views

Hi Cold Fusion Gurus

i have this simple piece of code, I need to put in an IF Statement where by if there is no results returned from the query, the output on the screen write "None".  Write now, if there are no results returned, it simply doesn't write anything.

          <!--- <cfif #get_matters.LocalCounsel# neq ""> --->
            <cfoutput query="GetMatterLC">
              <li>#GetMatterLC.Counsel#
                <cfif #LName# neq "">
                  | #GetMatterLC.LName#, #GetMatterLC.FName#
                </cfif>
              </li>
            </cfoutput>
        <!--- <cfelse>
            <li> </li>
          </cfif> --->

Please help!!

Thank you

    This topic has been closed for replies.
    Correct answer Joshua_Cyr

    You were almost there with your cfif.

    <cfif getmatterLC.recordcount GT 0>

       <cfoutput query="GetMatterLC">
                  <li>#Counsel#
                    <cfif LName neq "">
                      | #LName#, #FName#
                    </cfif>
                  </li>
                </cfoutput>

    <cfelse>

    <p>We are sorry, no records found.</p>

    </cfif>

    Also, because you are doing cfoutput of the query, you don't have to mention the query name as part of the variable inside the cfoutput.

    1 reply

    Inspiring
    February 10, 2010

    Best advice to all newbies when they are faced witha  problem: read the docs.  That's what they're there for.

    Read this:

    http://livedocs.adobe.com/coldfusion/8/htmldocs/Tags_p-q_17.html#1102316

    --

    Adam

    Participant
    February 10, 2010

    A Cameron -

    I appreciate the link but I learn better if there was a working model of what I am trying to achieve and then I study it, understand what the code is doing - then try apply that to future coding.

    But I do appreciate the link. :-)

    Joshua_CyrCorrect answer
    Participating Frequently
    February 10, 2010

    You were almost there with your cfif.

    <cfif getmatterLC.recordcount GT 0>

       <cfoutput query="GetMatterLC">
                  <li>#Counsel#
                    <cfif LName neq "">
                      | #LName#, #FName#
                    </cfif>
                  </li>
                </cfoutput>

    <cfelse>

    <p>We are sorry, no records found.</p>

    </cfif>

    Also, because you are doing cfoutput of the query, you don't have to mention the query name as part of the variable inside the cfoutput.