Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

coldfusion fetch mysql query question

New Here ,
Jul 14, 2009 Jul 14, 2009

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.

1.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jul 14, 2009 Jul 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


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 14, 2009 Jul 14, 2009
LATEST

Totally correct answer, thanks.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources