Skip to main content
Known Participant
February 1, 2011
Question

I want if query no get value above, apply the value of 1... To get value needed loop in line 4...

  • February 1, 2011
  • 2 replies
  • 1564 views
<cfquery datasource="mysqlcf_lse123polis" name="selectVisitorTimes" >
SELECT TimesVisited FROM Visitors WHERE countNumVisitor=#countNumVisitor#
</cfquery> 
//line 4
<cfparam name="TimesVisited" default="1">
I want if query no get value above, apply the value of 1... To get value needed loop in line 4...?
This topic has been closed for replies.

2 replies

BKBK
Community Expert
Community Expert
February 8, 2011

The full extent of what you wish to do is:

<cfquery datasource="mysqlcf_lse123polis" name="selectVisitorTimes" >
SELECT TimesVisited FROM Visitors WHERE countNumVisitor=#countNumVisitor#
</cfquery> 
//line 4
<cfparam name="selectVisitorTimes.TimesVisited" default="1">

However, the cfparam will never run! That is because the variable selectVisitorTimes.TimesVisited exists even when the query returns nothing. Owain's suggestion is about as good as it gets.
Known Participant
February 8, 2011

what if rather <cfset Visited = 1 />

have

<cfparam name="Visited" default="1">

???

BKBK
Community Expert
Community Expert
February 8, 2011

123polis123 wrote:

what if rather <cfset Visited = 1 />

have

<cfparam name="Visited" default="1">

<cfelse>

<!---Here the variable visited is undefined, so the cfparam will have the same effect as the cfset--->

</cfif>

Inspiring
February 1, 2011

Write a union query, selecting 1 in the other half.

Known Participant
February 1, 2011

you mean loop or give sample

Inspiring
February 1, 2011

I didn't mean loop, I meant union query.  If you don't know what that is, I've heard good things about the book, Teach Yourself SQL in 10 Minutes.

Alternatively, you can try the approach suggested by Owain North.  However, in your cfelse block, you'd have to use ColdFusion query functions, not a simple cfset.