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

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

New Here ,
Feb 01, 2011 Feb 01, 2011
<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...?
TOPICS
Getting started
1.3K
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
LEGEND ,
Feb 01, 2011 Feb 01, 2011

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

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 ,
Feb 01, 2011 Feb 01, 2011

you mean loop or give sample

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
Guide ,
Feb 01, 2011 Feb 01, 2011

Not really sure what you're asking, but how about a dirty:

<cfif selectVisitorTimes.RECORDCOUNT >

     <cfset Visited = selectVisitorTimes.colname />

<celse>

     <cfset Visited = 1 />

</cfif>

That'd work.

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
LEGEND ,
Feb 01, 2011 Feb 01, 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.

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 ,
Feb 01, 2011 Feb 01, 2011

in cfelse this is ok?

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

what you mean by "ColdFusion query functions" ?

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
LEGEND ,
Feb 01, 2011 Feb 01, 2011

The cfelse you suggested will not satisfy the requirements you stated in your original post.

By "ColdFusion query functions", I mean the functions in ColdFusion that enable you to create and manipulate query objects.  If you google that very string, and look for any offerings by adobe, you will quickly find the names of the three functions you need and instructions on how to use them.

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
Community Expert ,
Feb 08, 2011 Feb 08, 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.
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 ,
Feb 08, 2011 Feb 08, 2011

what if rather <cfset Visited = 1 />

have

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

???

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
Community Expert ,
Feb 08, 2011 Feb 08, 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>

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 ,
Feb 09, 2011 Feb 09, 2011

<cfparam name="cookie.countNumVisitor" default="-1">

<cfset countNumVisitor = cookie.countNumVisitor>

i used above but in FF Browser I got two cookie values in the two names of COUNTNUMVISITOR, How get only one?

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 ,
Feb 09, 2011 Feb 09, 2011

is any function check if cookies exist or not, without set up to default value?

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 ,
Feb 09, 2011 Feb 09, 2011

<cfcookie name="countNumVisitor" value="#countNumVisitor#" expires="never" domain=".polis.com" path="/">

<cfset cookie.countNumVisitor = selectVisitor.recordcount>

these two methods are correct both, to setup a cookie? site wide cookie...

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
Community Expert ,
Feb 09, 2011 Feb 09, 2011

123polis123 wrote:

<cfcookie name="countNumVisitor" value="#countNumVisitor#" expires="never" domain=".polis.com" path="/">

<cfset cookie.countNumVisitor = selectVisitor.recordcount>

these two methods are correct both, to setup a cookie? site wide cookie...

<cfcookie name="countNumVisitor" value="#selectVisitor.recordcount#" expires="never" domain=".polis.com">

and

<cfset cookie.countNumVisitor = selectVisitor.recordcount>

are both valid. However, the first gives you more control.

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
LEGEND ,
Feb 09, 2011 Feb 09, 2011
LATEST

If he's still using the query in the OP, the recordcount will always be one.  That means my suggestion of a union query was not appropriate.  Something like this should work.

select case when records > 0 then records else 1 end VisitorCount

from

(select count(*) records e

etc

) temp

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
Community Expert ,
Feb 09, 2011 Feb 09, 2011

123polis123 wrote:

is any function check if cookies exist or not, without set up to default value?

<cfif isDefined("cookie.countNumVisitors")>

</cfif>

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
Community Expert ,
Feb 09, 2011 Feb 09, 2011
function(){return A.apply(null,[this].concat($A(arguments)))}function(){return A.apply(null,[this].concat($A(arguments)))}function(){return A.apply(null,[this].concat($A(arguments)))}

123polis123 wrote:

<cfparam name="cookie.countNumVisitor" default="-1">

<cfset countNumVisitor = cookie.countNumVisitor>

i used above but in FF Browser I got two cookie values in the two names of COUNTNUMVISITOR, How get only one?


I would first delete any existing cookie values before setting a new one. To delete a cookie, do this

<cfcookie name="countNumVisitor" expires="now">

Alternatively, you could just overwrite the cookie value by resetting it.

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