Performance cfif vs cfswitch
With cfswitch code is more readable so no dought it should be
used.
But I am wondering if using cfswitch improves/affects
performance of website or no?
thanks
http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?catid=7&threadid=1348161#4900 124
Similar Messages
-
Is it possible to call CF functions dymanically?
Is it possible to call a ColdFusion function dynamically? For
example you might have a date variable: myDate that you want to
apply a ColdFusion date function to. However, the function itself
needs to be dynamic because you might want to call "dateFormat",
"timeFormat", "dateAdd", etc.
Is there a way to evaluate an expression like this?
<!-- defined the function to call and encapsulate the
dynamic variable name with brackets -->
<cfset functionToCall =
"DateFormat([myVariable],'MM/DD/YYYY')">
<cfset myDate = CreateODBCDate('03/19/1977')>
<!-- now replace the bracketed name with the actual
variable data (myDate) -->
<cfset fullString =
ReplaceNoCase(functionToCall,'[myVariable]','#myDate#','ALL')>
<!-- display the output -->
<cfoutput>
#evaluate(fullString )#
</cfoutput>
What I get here is an error message because there are invalid
characters in "fullString". When I simply cfoutput fullString the
text it produces looks perfect, its just that I need to find a way
to evaluate it.
Any ideas?
Thanks for taking the time to help.presumably, which function you need to use depends on some
condition...
so you can just use a <cfif> or <cfswitch> block
to check the condition
and use appropriate function...
you can even encapsulate it into your own function that uses
built-in cf
functions depending on some other argument passed.
e.g:
<cffunction name="myveryowndatefunction">
<cfargument name="mydate" required="yes">
<cfargument name='myotherargument" required="yes">
<cfif arguments.myotherargument eq something>
<cfreturn use_one_cf_function>
<cfelseif ...>
<cfreturn use_other_cf_function
<cfelse>
<cfreturn use_yet_another_cf_function>
</cfif>
</cffunction>
Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/ -
Translating months to Spanish equivalent
Hey all -
Simple yet elusive problem. I have a query looping over a
list of articles for one of my websites. Some of these articles are
in Spanish. Next to each article title is the date of the article.
I'm using a standard DateFormat to do this:
#dateformat(query.ArticleDate, "mmmm yyyy")#
That ArticleDate is a smalldatetime data type in my SQL
Server. Is there anyway to avoid a complex CFIF (or cfswitch)
checking the results of #dateformat(query.ArticleDate, "mmmm
yyyy")# and replacing them with the Spanish equivalent?
Gracias.longboardfin wrote:
> That ArticleDate is a smalldatetime data type in my SQL
Server. Is there
> anyway to avoid a complex CFIF (or cfswitch) checking
the results of
> #dateformat(query.ArticleDate, "mmmm yyyy")# and
replacing them with the
> Spanish equivalent?
set the locale to your preferred locale, for example (cf7):
<cfset oldLocale=setLocale("es_ES")>
then simply format it using the one of the LS methods:
#lsDateFormat(query.ArticleDate, "mmmm yyyy")#
though i strongly urge you to stick w/the standard masks
(FULL, LONG, MEDIUM,
SHORT)--you'll never be able to parse that custom mask back
to the original
datetime object if you ever have to. -
"Data truncation: Incorrect datetime value" Error Message
Hello,
I'm running Coldfusion 8 with a MySQL database. The s10Date
column is of type "datetime".
What would cause the following error to occur when I'm
entering data into the database?
Data truncation: Incorrect datetime value: '{ts '2008-09-03
17:16:01'}' for column 's10Date' at row 1
The error occurred in
C:\ColdFusion8\wwwroot\Websites\questnbs.info\components\DataMgr\DataMgr.cfc:
line 1602
Called from
C:\ColdFusion8\wwwroot\Websites\questnbs.info\components\DataMgr\DataMgr.cfc:
line 1170
Called from
C:\ColdFusion8\wwwroot\Websites\questnbs.info\components\DataMgr\DataMgr.cfc:
line 1633
Called from
C:\ColdFusion8\wwwroot\Websites\questnbs.info\parsed\quest_c_registrations.processregistr ationform.cfm:
line 37
Called from
C:\ColdFusion8\wwwroot\Websites\questnbs.info\parsed\quest_c_registrations.processregistr ationform.cfm:
line 5
Called from
C:\ColdFusion8\wwwroot\Websites\questnbs.info\parsed\quest_c_registrations.processregistr ationform.cfm:
line 1
Called from
C:\ColdFusion8\wwwroot\Websites\questnbs.info\fusebox5\Application.cfc:
line 228
Called from
C:\ColdFusion8\wwwroot\Websites\questnbs.info\fusebox5\Application.cfc:
line 218
Called from
C:\ColdFusion8\wwwroot\Websites\questnbs.info\fusebox5\fusebox5.cfm:
line 57
Called from
C:\ColdFusion8\wwwroot\Websites\questnbs.info\index.cfm: line 12
1600 : <cfquery name="qQuery"
datasource="#variables.datasource#" username="#variables.username#"
password="#variables.password#"><cfloop index="i" from="1"
to="#ArrayLen(aSQL)#" step="1"><cfif IsSimpleValue(aSQL
)><cfset temp =
aSQL>#Trim(PreserveSingleQuotes(temp))#<cfelseif
IsStruct(aSQL
)><cfset aSQL = queryparam(argumentCollection=aSQL
)><cfswitch
expression="#aSQL.cfsqltype#"><cfcase
value="CF_SQL_BIT"><cfif aSQL
.value>1<cfelse>0</cfif></cfcase><cfcase
value="CF_SQL_DATE">#CreateODBCDateTime(aSQL.value)#</cfcase><cfdefaultcase><cfif
ListFindNoCase(variables.dectypes,aSQL
.cfsqltype)>#Val(aSQL.value)#<cfelse><cfqueryparam
value="#aSQL
.value#" cfsqltype="#aSQL.cfsqltype#" maxlength="#aSQL
.maxlength#" scale="#aSQL.scale#" null="#aSQL
.null#" list="#aSQL.list#" separator="#aSQL
.separator#"></cfif></cfdefaultcase></cfswitch></cfif>
</cfloop></cfquery>
1601 : <cfelse>
1602 : <cfquery name="qQuery"
datasource="#variables.datasource#"><cfloop index="i"
from="1" to="#ArrayLen(aSQL)#" step="1"><cfif
IsSimpleValue(aSQL)><cfset temp = aSQL
>#Trim(PreserveSingleQuotes(temp))#<cfelseif
IsStruct(aSQL)><cfset aSQL
= queryparam(argumentCollection=aSQL)><cfswitch
expression="#aSQL
.cfsqltype#"><cfcase value="CF_SQL_BIT"><cfif
aSQL.value>1<cfelse>0</cfif></cfcase><cfcase
value="CF_SQL_DATE">#CreateODBCDateTime(aSQL
.value)#</cfcase><cfdefaultcase><cfif
ListFindNoCase(variables.dectypes,aSQL.cfsqltype)>#Val(aSQL
.value)#<cfelse><cfqueryparam value="#aSQL.value#"
cfsqltype="#aSQL
.cfsqltype#" maxlength="#aSQL.maxlength#" scale="#aSQL
.scale#" null="#aSQL.null#" list="#aSQL
.list#"
separator="#aSQL.separator#"></cfif></cfdefaultcase></cfswitch></cfif>
</cfloop></cfquery>
1603 : </cfif>
1604 :
Thank you in advance for your assistance.
SimonJust a note, I had the same problem and resolved it by making
sure my cfsqltype in cfqueryparam is cf_sql_timestamp instead of
cf_sql_datetime (which is not a valid value).
Also, just a note that when working with a datetime value in
cfqueryparam, using cf_sql_date for cfsqltype will truncate the
time to 00:00:00. -
Ok, I got some code working on a page, and would like to now
see about
putting it in a UDF...
The UDF right now looks like:
<cffunction name="classSort" output="false">
<cfargument name="eventType" type="string"
required="yes">
<cfset temp_var=1>
<cfloop list="arguments.eventType" delimiters=","
index="i">
<cfset full_var_temp_var=#i#>
<cfset temp_var=temp_var+1>
</cfloop>
<cfswitch expression="full_var_1">
<cfcase value="f">
<cfif var_temp_2 gte 15>
<cfif rates.C gte 2>
<cfif rates.B gte 2 or rates.D gte 2>
<cfif rates.A gte 2 and rates.B gte 2>
<img src="images/A1.gif" width="94" height="29">
<cfelseif rates.D gte 2 and rates.E gte 2>
<img src="images/C1.gif" width="94" height="29">
<cfelse>
<img src="images/B1.gif" width="94" height="29">
</cfif>
</cfif>
</cfif>
</cfif>
</cfcase>
</cfswitch>
</cffunction>
And I'd be passing arguments in the form of functin(f,30)
What I'm trying to do is get the image filename sent back so
I can display
it on the page.
Am I on the right track here???Well, I changed the function to:
<cffunction name="classSort" output="false">
<cfargument name="eventType" type="string"
required="yes">
<cfif eventType gte 15>
<cfif rates.C gte 2>
<cfif rates.B gte 2 or rates.D gte 2>
<cfif rates.A gte 2 and rates.B gte 2>
<cfset retImage="images/A1.gif">
<img src="images/A1.gif" width="94" height="29">
<cfelseif rates.D gte 2 and rates.E gte 2>
<img src="images/C1.gif" width="94" height="29">
<cfelse>
<img src="images/B1.gif" width="94" height="29">
</cfif>
</cfif>
</cfif>
</cfif>
<cfreturn retImage>
</cffunction>
Now my question is, in the code that's calling the function,
the image isn't
displaying..... I tried <img
src="#classSort(foilCount.recordcount)#">
Is that not correct?
"Ian Skinner" <[email protected]> wrote in message
news:[email protected]...
> Steve Grosz wrote:
>> Ok, I got some code working on a page, and would
like to now see about
>> putting it in a UDF...
>>
>> The UDF right now looks like:
>>
>> <cffunction name="classSort" output="false">
>> <cfargument name="eventType" type="string"
required="yes">
>>
>> <cfset temp_var=1>
>> <cfloop list="arguments.eventType" delimiters=","
index="i">
>> <cfset full_var_temp_var=#i#>
>> <cfset temp_var=temp_var+1>
>> </cfloop>
>>
>> <cfswitch expression="full_var_1">
>> <cfcase value="f">
>> <cfif var_temp_2 gte 15>
>> <cfif rates.C gte 2>
>> <cfif rates.B gte 2 or rates.D gte 2>
>> <cfif rates.A gte 2 and rates.B gte 2>
>> <img src="images/A1.gif" width="94"
height="29">
>> <cfelseif rates.D gte 2 and rates.E gte 2>
>> <img src="images/C1.gif" width="94"
height="29">
>> <cfelse>
>> <img src="images/B1.gif" width="94"
height="29">
>> </cfif>
>> </cfif>
>> </cfif>
>> </cfif>
>> </cfcase>
>> </cfswitch>
>>
>> </cffunction>
>>
>> And I'd be passing arguments in the form of
functin(f,30)
>>
>> What I'm trying to do is get the image filename sent
back so I can
>> display it on the page.
>>
>> Am I on the right track here???
>
> Wow that is some obtuse logic there. I'm going to go
with that you know
> why you are doing all that looping at the beginning.
>
> The first thing I'm seeing is an incompatibility with
output="false" and
> <cfif...>...<img ...> logic.
>
> This code is attempting to output <img...> tags
but that is disallowed in
> the <cffunction...> tag. You either need to allow
output - which would
> also include all the white space in the function if
steps are not taken to
> control it. Or save the <img....> tag code into a
string variable and
> then return that variable at the end of the function
with a <cfreturn ...>
> tag.
>
> -
Mixing next n records with cfswitch order by problem
Hello;
I'm trying to make 2 types of page navigation work together. both work fine independently, but when I put my next n record code together with my change order by code, when you hit the next button, it goes back to the set default for the order by. I know I need to change some code logic in my scripts that run the next n records, but I'm not sure what I need to change in it to make it all work together properly. I am attaching the code, in it's rawest form, but all code is here for both features.
<cfparam name="sort" default="1">
<cfquery name="getMerch" datasource="#APPLICATION.dataSource#">
SELECT merchID, MerchName, MerchDescription, MerchPrice, MYFile, CategoryID
FROM Merchandise
WHERE CategoryID = 2
ORDER BY
<cfswitch expression="#sort#">
<cfcase value="1">MerchName</cfcase>
<cfcase value="2">MerchPrice</cfcase>
</cfswitch>
</cfquery>
<cfset rowsPerPage = 3>
<cfparam name="URL.startRow" default="1" type="numeric">
<cfset totalRows = getMerch.recordCount>
<cfset endRow = min(URL.startRow + rowsPerPage - 1, totalRows)>
<cfset startRowNext = endRow + 1>
<cfset startRowBack = URL.startRow - rowsPerPage>
<cfoutput>
<!--- changes the order by --->
<cfif sort is 1>
<a href="#CGI.script_name#?sort=#IIF(sort is 1, '2', '1')#" class="pre2Nav">Order By Price</a>
<cfelse>
<a href="#CGI.script_name#?sort=#IIF(sort is 2, '1', '2')#" class="pre2Nav">Order By Product</a>
</cfif>
<!--- my next n buttons --->
<cfif startRowBack GT 0>
<a href="#CGI.script_name#?startRow=#startRowBack#" class="pre2Nav">< Back</a>
</cfif>
<cfif startRowNext lte totalRows>
<a href="#CGI.script_name#?startRow=#startRowNext#" class="pre2Nav">More ></a>
</cfif>
</cfoutput>
<cfloop query="getMerch" startRow="#URL.startRow#" endRow="#endRow#">
<cfoutput>
All my output goes here
</cfoutput></cfloop>
Can anyone help me get this to work together? is it possible? and more importantly, how hard is it going to be to do this?
Thank you.if I use this:
<cfdump var = "#isDefined('sort')#">
I get YES as the output, even when I hit the next button and change the category.
If I use this:
<cfdump var = "isDefined('sort')>
all I get is this:
isDefined('sort') -
cflayout , cfform , cfif - not working right
Greetings,
CF Ver: 8,0,1,195765
<cfajaximport tags="cflayout-tab,cfform,cftooltip">
DW CS5
<cflayoutarea source="resource_upload.cfm"
Form elements are:
-- res_type = radio
-- res_yy = text
-- res_title = text
-- res_doc = file
I have a form embedded in a tab of a <cflayout>. The form works fine
external to the <cflayout>. When I say it works fine, I mean that
when the form fields are evaluated for emptiness with <cfif>(s) all
processes as expected.
However, when I embed the form inside the <cflayout> the <cffile>
form field no longer evaluates properly for emptiness. Whether the
field is empty or not, it always processes as if there is content in it.
I have even tried setting a variable using <cfparam> and still cannot
get it to evaluate as it does outside the <cflayout>. I have also used
the len and trim functions as well performing the evaluations.
Is there something I am missing to make the form function inside the
<cflayout> as it does outside of it?
Thanks in advance.
Leonard BHey Adam,
Below is the code that I am working with.
================================
<!--- The cflayout --->
<div align="center">
<div style="clear: both; padding: 25px 0px 0px 0px; width: 600px" align="left">
<div style="border: 5px solid #900">
<cflayout type="tab" align="left" name="resource_management" tabposition="top" style="margin-top: -3px">
<cflayoutarea name="resource_upload" overflow="auto" style="background-color: ##FC0; height: 400px;" title="Resource Upload">
<div style="clear: both; padding: 10px 10px 10px 10px">
<cfform action="insert_resource_upload_processing.cfm" target="resource_upload" method="post" enctype="multipart/form-data" name="form_01" id="form_01" class="formBody" lang="en" dir="ltr" xml:lang="en">
<div style="clear: both; float: left; padding: 0px 10px 0px 0px">
<label for="resource_yy" class="formLabel"> YEAR</label><br />
<cfinput type="text" name="resource_yy" class="formInput" id="resource_yy" style="text-align: center; width: 50px;" dir="ltr" lang="en" typeahead="no" showautosuggestloadingicon="true">
</div>
<div style="float: left">
<label for="resource_grp" class="formLabel"> RESOURCE GROUP</label><br />
<cfselect enabled="No" name="resource_grp" size="1" class="formSelect" id="resource_grp" dir="ltr" lang="en" multiple="no">
<option value="None" selected="selected">- Select Group -</option>
<option value="Tests">Tests / Answer Keys</option>
<option value="Digests">Digests</option>
<option value="PowerPoints">PowerPoints</option>
<option value="Other Documents">Other Documents</option>
</cfselect>
</div>
<div style="clear: both; padding: 10px 0px 0px 0px">
<label for="resource_title" class="formLabel"> RESOURCE TITLE</label><br />
<cfinput type="text" name="resource_title" class="formInput" id="resource_title" style="width: 565px;" dir="ltr" lang="en" typeahead="no" showautosuggestloadingicon="true">
</div>
<div style="clear: both; padding: 10px 0px 0px 0px">
<label for="resource_pwrpnt" class="formLabel"> RESOURCE POWERPOINT</label><br />
<cfinput type="file" name="resource_pwrpnt" class="formFile" id="resource_pwrpnt" dir="ltr" lang="en" size="78" xml:lang="en">
</div>
<div style="clear: both; padding: 10px 0px 0px 0px">
<div style="float: left; padding: 0px 10px 0px 0px">
<cfinput type="submit" name="btn_post" class="buttonSubmit" id="btn_post" style="letter-spacing: 1px; width: 125px;" dir="ltr" lang="en" value="POST RESOURCE"></div>
<div style="float: left">
<cfinput type="reset" name="btn_clear" class="buttonReset" id="btn_clear" style="letter-spacing: 1px; width: 125px;" dir="ltr" lang="en" value="CLEAR FIELDS"></div>
</div>
</cfform>
</div>
</cflayoutarea>
<cflayoutarea name="resource_delete" overflow="auto" style="background-color: ##CC9; height: 400px;" title="Resource Delete">
<p>Content tab 2 here</p>
</cflayoutarea>
</cflayout>
</div>
</div>
</div>
<!--- The action page --->
<cfparam name="form.resource_pwrpnt" default="None">
<p>
<cfif isdefined('form.resource_yy') and trim(form.resource_yy) eq "">
Year Resource year not provided<br />
<cfelse>
Year <cfoutput>#form.resource_yy#</cfoutput>
</cfif></p>
<p>
<cfif isdefined('form.resource_grp') and trim(form.resource_grp) eq "None">
Group: Resource group not provided<br />
<cfelse>
Group: <cfoutput>#form.resource_grp#</cfoutput>
</cfif></p>
<p>
<cfif isdefined('form.resource_title') and trim(form.resource_title) eq "">
Title Rescource title not provided
<cfelse>
Title <cfoutput>#form.resource_title#</cfoutput>
</cfif></p>
<p>
<cfif isdefined('form.resource_pwrpnt') and trim(form.resource_pwrpnt) eq "">
PwrPnt Resource powerpoint not provided
<cfelse>
PwrPnt <cfoutput>#form.resource_pwrpnt#</cfoutput>
</cfif></p>
<div style="clear: both; padding: 5px 0px 0px 0px">
<cfform action="insert_resource_upload_form.cfm" method="post" enctype="multipart/form-data" name="form_01" id="form_01" class="formBody" lang="en" dir="ltr">
<cfinput type="submit" name="btn_prev_01" class="buttonGoback" id="btn_prev_01" style="letter-spacing: 1px; width: 135px;" dir="ltr" lang="en" value="PREVIOUS SCREEN" xml:lang="en">
</cfform>
</div> -
Hi everyone,
I'm currently working on optimizing a report that takes about
2 minutes to load. The main reason is that it has sooo much data. I
noticed 2 things that i might be able to improve on...first there
are a ton of <cfif> statements and second there are so many
Query of Queries for each record. Basically I need help with these
2 things:
1) There are quite a few boolean fields. Currently the logic
is on the .cfm page meaning for a certain boolean field, we use
<cfif qryGetPipelines.pipebdw_is_me_tech_assistance eq
1>
Y
<cfelse>
N
</cfif>
My question is that would it better and more efficient if i
just use a CASE WHEN pipebdw_is_me_tech_assistance = 1
THEN....statement in the query and that way i don't have to do the
<cfif> on the .cfm page?
2) My second question is: let's say the report pulls up 400
records, i then loop through those records and display the
different fields and i also perform about 10 Query of Queries in
each loop to get fields that have more then 1 record. So bascially,
for each of the 400 records, i have 10 additional Query of Queries
and though it's only about 15 - 20 ms per query...when you add
multiply 10 * 400 it takes up quite a lot of time. Is there any
other way around this??
Thank you so much for all your help.
Anju@Ian - Thanks for your help Ian and the answer to your
question is yes i do plan to put the CASE statement in the Sql
query, currently the logic is being done by using <cfif> on
the .cfm page.
@Dan - Thanks for your help as well. Can you please give me a
little more info as to what would be a more effiicient way then
looping through a query in order for me to display about 30 columns
(fields) of data for anywhere from 400 - 1000 records?
Thanks again for all your help -
CFC vs. Query performance
I created a discussion board. Each entry displays the
preferences of the user who posted the entry, such as 'Allow
Private Messages', 'Allow Emails' etc. When looping through the
entries, I have to query the database to get the preferences for
each individual 'poster'. Because I thought it would increase
performance, I created a CFC method and call the Object into the
session scope. Then I initiate the method when looping through the
results and setting a variable in the THIS scope in the instance to
the query result value.
When comparing the two ways of doing it, there's a four-fold
increase in load time using the CFC, this doesn't seem right and I
suspect I am doing something wrong.
Below are the two different approaches, maybe someone can
help me:
Without CFC:
<cfoutput query="results">
<cfquery name=getPoster datasource="xxx">
select first_name
from users
where user_id = #results.user_id#
</cfquery>
</cfoutput>
With a CFC:
CFC Code:
<cfcomponent>
<cfset THIS.user_data_id = 0>
<cffunction name="getPosterPrefs" access="public"
returntype="query">
<cfargument name="user_data_id" required="yes"
type="numeric">
<cfquery name="getposter" datasource="xxx">
SELECT allow_pm, pm_ignore_list, show_email
FROM forum_user_data
WHERE user_data_id = #THIS.user_data_id#
</cfquery>
<cfreturn getPMprefs1>
</cffunction>
</cfcomponent>
In the page:
<cfif (not structKeyExists(session, "replyPrefs"))>
<cflock name="lock_replyPrefs" timeout="5"
type="exclusive">
<cfobject component="/tvocomponents.forums"
name="session.replyPrefs">
</cflock>
</cfif>
<cfoutput query="results">
<cfset session.replyPrefs.user_data_id =
#getReplyPoster.user_data_id#>
#message#
<cfif
#session.replyPrefs.getPosterPrefs(getReplies.thread_reply_user_id).allow_pm#
eq 1>Allow Private Messages</cfif>
</cfoutput>
Thanks for any help.Well yes, all you did was move your query into a CFC that
must be
initiated for every user in your display. So you are still
doing each
and every query you where doing before, and on top of that
you are
creating an object around it. This is not going to improve
performance
in any way.
I'm probably not the one to help you improve this with OOD.
I'm not
that good at it myself. I'm still struggling with beans,
DAOs,
gateways, factories, and MVP designs and how you put them all
together
myself.
But at the most basic level, what you want to remove is the
individual
queries run sequentially, whether you use procedural or OOP
logic.
Ideally you would run one query that gets all the data for
all the users
you need to know about in one swoop and save this as long as
you need
it, so you don't have to do it again unnecessarily. -
Adding an if / cfswitch statement to a query missing peramiters
Hello;
I'm trying to add a feature into a page I made. It has a lot going on, so I'll try and give you the basic function I'm trying to add.. and as little of the other logic as possible.
I want to add a dropdown menu to this page, I have 2 querys running it. one, runs the dropdown.. here is the code for that:
<CFQUERY name="cata" datasource="#APPLICATION.dataSource#" cachedwithin="#CreateTimeSpan(0, 6, 0, 0)#">
select subName, subID
FROM merchSubCat
ORDER BY subName
</CFQUERY>
<form Name="category" method="get" Action="wallProduct.cfm?id=#subID#">
<select name="CategoryID" size="1" class="selectstyle" onChange="category.submit();">
<option value=""> --Select a Category-- </option>
<CFOUTPUT query= "cata">
<option value="#subID#">#subName#</option>
</CFOUTPUT>
</select></form>
ok, simple enough. It takes the info from my db and makes a little menu out of it. click on one of the selections, and it will pass a url.id to the same page. This query is the main query that runs the page. I need it to serve up the first set of records by default, and if you select from the drop down, the according records will be brough up. here is my query to add this feature.
<cfquery name="getMerch" datasource="#APPLICATION.dataSource#">
SELECT merchID, MerchName, MerchDescription, MerchPrice, MYFile, subID, CategoryID
FROM Merchandise
WHERE
<cfif isDefined ("#url.id#")>
<cfswitch expression="#url.id#">
<cfcase value="1">subID = 1</cfcase>
<cfcase value="2">subID = 2</cfcase>
<cfcase value="3">subID = 3</cfcase>
</cfswitch>
<cfelse>
subID = 1
</cfif>
</cfquery>
When my page loads, there is no ID in the url, and my code is not liking this and throwing an erro as such:
Element ID is undefined in URL.
The error occurred in C:\Websites\187914kg3\magWall\wallProduct.cfm: line 19
17 : FROM Merchandise
18 : WHERE
19 : <cfif isDefined ("#url.id#")>
20 : <cfswitch expression="#url.id#">
21 : <cfcase value="1">subID = 1</cfcase>
This is my problem, and I'm sure it's something silly I'm forgetting ehre. I've done this b4. How do I make this work so that by default, subID = 1 is shown when the page loads, and the others are shown when you use the dropdown menu.
I also spoke of other logic on this page. there is a next n button running this query, as well as a cfswitch to switch the order of the records, using the ORDERBY in my query. But I want to get this dropdown menu working before I add in all this other logic.
can anyone help me? I'm having a mental block on this problem.
thank you.Ken, yours works nice. I thought of the cfparam afte
r I posted, but left the default blank, so it threw an error.
Now my problem is an error with my dropdown menu. It says sudID is undefined in the form variables for this select. here is the
error, and code.. I tried a few different approaches on this and right now, nothig is fixing it.
My error:
Variable SUBID is undefined.
The error occurred in C:\Websites\187914kg3\magWall\wallProduct.cfm: line 89
87 : <table width="100%" border="0" cellspacing="0" cellpadding="0">
88 : <tr>
89 : <td colspan="3" align="center" valign="top"><form Name="category" method="get" Action="wallProduct.cfm?ID=#subID#">
90 : <select name="subID" size="1" class="selectstyle" onChange="category.submit();">
91 : <option value=""> --Select a Category-- </option>
My code:
<CFQUERY name="cata" datasource="#APPLICATION.dataSource#">
select subName, subID
FROM merchSubCat
ORDER BY subName
</CFQUERY>
<form Name="category" method="get" Action="wallProduct.cfm?ID=#subID#">
<select name="subID" size="1" class="selectstyle" onChange="category.submit();">
<option value=""> --Select a Category-- </option>
<CFOUTPUT query= "cata">
<option value="#subID#">#subName#</option>
</CFOUTPUT>
</select></form>
am I missing something here? -
cfif structkeyexists(form, "btnSubmit") overridding
I have a form that submits to itself instead of an action page.
This is my submit button : <input type="submit" name="btnSubmit" style="width: 108px" value="Submit">
When the form is submitted, I check for the existence of the submit button and then do processing :
<cfif structkeyexists(form, "btnSubmit")>
<cftransaction>
<!--- Deteremine if any of the checkboxes were checked from the form. Since the checkboxes name is 'del=#urdn_number#',
check to see if the first four characters are 'Del_'. If it is, perform a loop and extract the the urdn number into
the variable select_urdn_number --->
<cfif isDefined("form.fieldnames") and mid(form.fieldnames,1,4) is "Del_">
<cfloop index="i" list="#form.fieldnames#" delimiters=",">
<cfset select_urdn_number = listlast(i,"_")>
I basically have rows of data and each row contains a checkbox and I process all the transactions simultaneously that are checked.
What is happening now is that it seems to be treating form.btnSubmit as a form variable and attempting to insert it into the table and it is blowing up.
When I did this using an action page, there was no need to check for form.btnSubmit and the inserts worked without any problems.
How can I get around this problems ?... which values were checked with the checkboxes. For example, if the form contains 10 records/checkboxes and only 4 are checked, and table updated, how do I produce a report showing those four that were checked ?
To get a list of all of the the selected "urdn" values, create a list variable and append each #select_urdn_number# to the list inside your cfloop.
<cfif structkeyexists(form, "btnSubmit")>
<!--- initialize the list --->
<cfset allUrdnNumbers = "">
<cfloop index="currentField" list="#form.fieldnames#">
<cfif mid(currentField,1,4) is "Del_">
<cfset select_urdn_number = listlast(currentField,"_")>
<!--- append each value to your list --->
<cfset allUrdnNumbers = listAppend(allUrdnNumbers, select_urdn_number)>
... other code ...
</cfif>
</cfloop>
... Then use the list of numbers generate the reports ie #allUrdnNumbers#
</cfif>
But if that is all you need, the cfloop code is unecessary. If you give all of the checkboxes the same name, and set the "value" to the #urdn# number, you would already have a list. Without jumping through all of the hoops and loops (see my first response above). -
Defining form recipients by CFSWITCH?
I am working with a form that has several check boxes on it. All of the check boxes have the same name so when the form processes I get a response like, check1,check2,check3 etc...
I want to set this up so that depending on what box(es) are checked different e-mail addresses will receive the form data.
I had tried using CFIF statements like with each checkbox individually named.
<cfif #FORM.check01# is "one">
<cfset emailRecip01="[email protected]">
</cfif>
<cfif #FORM.check02# is "two">
<cfset emailRecip02="[email protected]">
</cfif>
<cfif #FORM.check03# is "three">
<cfset emailRecip03="[email protected]">
</cfif>
<cfmail to="#emailRecip01# #emailRecip02# #emailRecip03#"
subject="Form Response"
from="[email protected]"
type="html">
This works fine if there is one address per checkbox, but I have two addresses and 11 check boxes.
Because of this I tried to use a CFSWITCH command and setup the following commands (shortened for this post).
<cfswitch expression="#FORM.checkBox#">
<cfcase value="one;two" delimiterters=";">
<cfset eAddress1="[email protected]">
</cfcase>
<cfcase value="three" delimiters=";">
<cfset eAddress2="[email protected]">
</cfcase>
<cfdefaultcase>
<cfset eAddress1="[email protected]">
<cfset eAddress2="">
</cfdefaultcase>
</cfswitch>
<cfmail to="#eAddress1# #eAddress2#"
subject="Form Response"
from="[email protected]"
type="html">
I am only receiving e-mails at the <cfdefaultcase> address. Why is this not working?
Thanks,
JeremiahHi, I actually was able to find a solution based on both your suggestions. Instead of using listfind, I used list length and separated the check boxes into two groups, checkbox1 and checkbox2. Then I used CFSET to check the length of the string returned, delimited by commas. From this I was able to write conditional statements, code below.
<cfset listLength01 = ListLen("#FORM.checkBox1#", ",")>
<cfset listLength02 = ListLen("#FORM.checkBOx2#", ",")>
<cfif #listLength01# GREATER THAN "0">
<cfset emailRecip01="[email protected]">
</cfif>
<cfif #listLength02# GREATER THAN "0">
<cfset emailRecip02="[email protected]">
</cfif>
<cfif #listLength01# is "0" and #listLength02 is "0">
<cfset emailRecip01="[email protected]">
</cfif>
<cfmail to="#emailRecip01#,#emailRecip02#"
subject="Form response"
from="[email protected]"
type="html">
Thanks to both of you both of your help!
Jeremiah -
cfif isDefined("url.Message")
does any one know what this <cfif
isDefined("url.Message")> is used for?It checks for the Message URL parameter.
If it is found, it will perform the code within the
<cfif></cfif> block.
If it is not found, it won't do anything.
http://livedocs.adobe.com/coldfusion/7/htmldocs/00000274.htm#1100123
http://livedocs.adobe.com/coldfusion/7/htmldocs/00000520.htm#1106482
Ken Ford
Adobe Community Expert
Fordwebs, LLC
http://www.fordwebs.com
"Coldfusionstudent" <[email protected]>
wrote in message news:f2283r$6e0$[email protected]..
> does any one know what this <cfif
isDefined("url.Message")> is used for? -
I have created a quote report with narratives around the opportunity, opportunity-product, and account information. The report contains a pivot table.
I'm getting very hit or miss performance results on the report. Sometimes the report runs faster for all opportunities compared to when its prompted with an opty id from a web link.
Any thoughts? There doesn't seem to be one column that makes a difference.
Also this is not an analytical report as the quotes need to be generated same day.Hi Shaik,
Please remove all the join select queries and use 'for all entries' varaiant of the select query. Check whether you can create and use indexes in ur queries.
Thanks and Regards,
Saurabh Chhatre -
I have a performance issue with a query - it would be something like -
select col1,col2, sum(col3), get_val(col_4)
from table1
where
get_val(col_4) is not null
group by col1,col2, get_val(col_4)
I have simplified this but it is something similar. This works great - performance is great. Now I commented out the where clause as I needed to populate null values - and that's it the query does not retrieve the resultset - it keeps running forever. With the where clause it comes back in 60 seconds. There is only one row out of 560 rows that has null value for col_4 which i need to display.
Any help is appreciated.The only difference I notice between the two sqls is HASH(UNIQUE) -
with IS NOT NULL in where clause -
SELECT STATEMENT ALL_ROWS 1598 1 209
HASH(UNIQUE) 1598 1 209
HASH(GROUP BY) 1598 1 209
When is not null is removed from the where clause -
SELECT STATEMENT ALL_ROWS 1598 1 206
HASH(GROUP BY) 1598 1 206
I'm guessing that the index is being used in the first scenario and not in the second. Any idea/suggestion as to how to over come this?
Thanks
Maybe you are looking for
-
How can I move contacts from ipod touch 2nd to ipod touch 4th generation
How can I move contacts from ipod touch 2nd to ipod touch 4th generation?
-
Forum, I'm making a zoomable and panable graphic and I have used four nested MCs as follows: main_mc->zoom_mc->pan_mc->content_mc. Main is top level and contains everything, zooming is done on zoom_mc, panning on pan_mc and my content is in content_m
-
To buy, or Not to buy? That is the qeustion??
Before the Ipad came out, I was seriously considering getting a Netbook. I already have a Laptop and Desktop at home. Waiting for the Ipad 3g to come out and considering to buy the 64gb one. Have read reviews that all the Ipad is is a glorified Iphon
-
A bounce question relate to the logic arpeggitar
I can hear the arpeggitor works when it is in edit mode but after I bounce it to mp3 it only has chord. what is wrong with that? thanks
-
Menu buttons won't work after publishing iWeb site
Once i publish my site from iWeb and then go online to check the site, i try to navigate through my new site's pages by clicking each of the menu buttons at the top of the page. After I click one and the page changes, the menu buttons stop working an