Skip to main content
Known Participant
June 6, 2006
Question

in-line if statements?

  • June 6, 2006
  • 3 replies
  • 1180 views
i'm trying to set a variable based on certain conditions...
in the past i've always done it like this:
<cfif x is true>
<cfset i = 5>
<cfelse>
<cfset i = 0>
</cfif>

now i know i can do an inline condition with php, but not sure if there is an equivalent in cf...for those familiar with php, this is what i'm after:
$i = ($x?5:0);

tia
This topic has been closed for replies.

3 replies

Known Participant
June 8, 2006
thanks phil..not the first time you've solved my problem! :)
Inspiring
June 7, 2006
> The cgi variable is either 1 or 0, which is hardly complex...am I missing
> something?

CGI is a built-in scope which holds the CGI variables the webserver passes
to CF. When you go <cfset CGI = "foo">, you're actually setting
VARIABLES.CGI. When you REFER to "CGI" in an expression, CF assumes you're
talking about the CGI scope (which is a structure).

Short version: don't use CGI as a variable name.

--
Adam
Known Participant
June 7, 2006
i guess i didnt make myself clear then..
i'm not setting a variable called cgi, i'm referencing a cgi variable...the variable cgi.server_port is numeric, so there should be no issue when checking the value: iif(cgi.server_port EQ 80, "1", "0")

this throws the error i stated above.
Known Participant
June 6, 2006
ok so i've found an answer..sortof.

iif() works, except that any cgi variable is throwing an error:
"Complex object types cannot be converted to simple values."

The cgi variable is either 1 or 0, which is hardly complex...am I missing something?