Skip to main content
Participant
July 14, 2009
Question

coldfusion fetch mysql query question

  • July 14, 2009
  • 2 replies
  • 1041 views

Hi:

Here is my coldfusion code:

<cfquery name = "query" datasource = "cfmysql" result = "result">
     SELECT COUNT(*) FROM students WHERE gender = 'boy'
</cfquery>

And then I want to check if value is greater than 0. I then do:

<cfif existSearchHintsQuery.COUNT(*) gt 0>

But coldfusion gives me an error at the * character, the colume of the mysql result is "COUNT(*)", so I really need the * character.

How do I fetch that count number?

Thanks.

    This topic has been closed for replies.

    2 replies

    cpthk0Author
    Participant
    July 14, 2009

    Totally correct answer, thanks.

    Inspiring
    July 14, 2009

    You need to use an alias so you can access the COUNT(*) like any other column:

     <cfquery name="yourQueryName" datasource="cfmysql" result="result">
        SELECT COUNT(*) AS TotalStudents FROM students WHERE gender = 'boy'
    </cfquery>


    <cfif yourQueryName.totalStudents GT 0>
    ... do something ...
    </cfif>

    Also, read up on using cfqueryparam  (if you are not using it already)

            http://livedocs.adobe.com/coldfusion/8/Tags_p-q_18.html