Cfquery questions
I am attempting to modify a web page that I did not write and
I have about 30 minutes of experience with coldfusion and
databases. I am having trouble putting the results of a cfquery
into the order I would like them displayed in.
I have read and understand I can include an “order by
…” to put results into any order I like. The problem is
I would like them sorted by a derived field that is not included in
the database. I have a column (?) labeled as “code”.
Code contains items such as “HG3465-85”. I can use
“order by” to list results alphanumerically, but I want
the results listed by the numeric portion only.
After a little reading I attempted:
Order By right(code,7)
Unfortunately, it did not work. What do I need to do?
Thanks in advance.
quote:
Originally posted by:
bj132
I am attempting to modify a web page that I did not write and
I have about 30 minutes of experience with coldfusion and
databases. I am having trouble putting the results of a cfquery
into the order I would like them displayed in.
I have read and understand I can include an “order by
…” to put results into any order I like. The problem is
I would like them sorted by a derived field that is not included in
the database. I have a column (?) labeled as “code”.
Code contains items such as “HG3465-85”. I can use
“order by” to list results alphanumerically, but I want
the results listed by the numeric portion only.
After a little reading I attempted:
Order By right(code,7)
Unfortunately, it did not work. What do I need to do?
Thanks in advance.
You need to use your database's string functions instead of
cold fusions.
Similar Messages
-
I have a question (actually two) about how caching works with cfquery so I can make sure that what I'm doing on our website makes sense. (We're on CF10)
I have a database that stores certain details about each of the web pages on our site. Contact ID, title, date added/updated, whether it's a recent or featured item, etc. The unique identifier for each page is the path (/folder/subfolder/page.cfm). Since out site is organized in several major topic areas, there's a column to identify which topic the page is in (and that's the same as the folder name that set of pages resides in).
Some or topics get tons of hits, and some get very few, so I've been doing this:
<cfquery name="getalltopics" datasource="dsn" cachedwithin="#createtimespan(0,1,0,0)#">
SELECT (columns I need
FROM pages
WHERE topic = <cfqueryparam value="#topicname#" cfsqltype="cf_sql_varchar">
</cfquery>
<cfquery name="getpagedetails" dbtype="query">
SELECT (columns I need)
FROM getalltopics
WHERE page_id = <cfqueryparam value="#page_path#" cfsqltype="cf_sql_varchar">
</cfquery>
So here's my question. I know that caches only come into play if the query that's being run identically matches the one that's cached. So in my mind, the fist query would make an individual cache of each of our topics, as the pages were viewed during the day. My second cache would grab the page details from the first, with several topics cached, how would the second one know which cache to find the page details in? The query works, and is fast, but I'm just wondering if I need to specify the topic ID in the second query.
My second question is about cache time. If I do createtimespan(0,1,0,0), does that cache last for an hour after it's created, or does it last for an hour after the last time that query is run?
Thanks!What I ended up doing was creating a variable-based query name, named after the current topic, like so:
<cfset qname = "q" & topic_name>
<cfquery name="#qname#" datasource="dsn" cachedwithin="#createtimespan(0,1,0,0)#">
SELECT (columns I need)
FROM pages
WHERE topic = <cfqueryparam value="#topicname#" cfsqltype="cf_sql_varchar">
</cfquery>
<cfquery name="getpagedetails" dbtype="query">
SELECT (columns I need)
FROM #qname#
WHERE page_id = <cfqueryparam value="#page_path#" cfsqltype="cf_sql_varchar">
</cfquery>
This way I (in theory) have a unique cache for each topic, and my second query draws from that cache.
Upon implementation, I've noticed a significant reduction in database hits (since we still use Access on this site, any hit creates an .ldb file, so I can easily tell if it's getting hit). Prior to the change, the ldb file was basically continuously there, appearing and reappearing a few times per second. Now, several minutes can go by with no ldb, even at the peak of the day, and pages are getting rendered almost instantly. If I add up all my query execution times for a page, I'm getting 5-7 ms total.
So it has to be doing something. -
Dynamic column name in cfquery
I have a scenario in which database column names are in a
format COLUMN1, COLUMN2, ...COLUMNn. Number of column is not known
while coding. But usually the column names are hard code while
accessing the cfquery result like
cfqueryresult.COLUMN1.
I want to get the column names from
'cfqueryresult.ColumnList' and from that result i want to fetch the
column values.
Is it possible to achieve this in coldfusion?quote:
Originally posted by:
Dan Bracuk
quote:
Originally posted by:
Newsgroup User
And then start planing for the normalization of your database
because that is a classic de-normalized pattern that just leads to
more and more difficulties maintaining your application. Just like
this one you have just experienced!
That wasn't my interpretation. I have some reports where the
contents of a select clause depend on user input. It results in a
similar scenario to what was described in the OP.
Or maybe the OP was trying to write generic code that could
be applied to arbitrary tables.
That was the situation which resulted in my question that you
and Ian answered so helpfully: I use an Access template in which
there are forms to facilitate entry of value lists (list-id, value,
and label) and a metatable that describes each column of the actual
working table , identifies any value-list that column references,
and includes the prompt and (after processing) the HTML for that
web page element. After I define the working table in the metatable
I run a VB procedure that creates the working table and generates
all the HTML in the metatable. Finally my generic ASP (and, coming
soon, ColdFusion) references the metatable and the working table to
generate an empty form, display a form populated from a DB row for
editing, assign form values to a DB row, or delete a DB row. Same
code, any table; all I have to do is define the table and the
value-lists it needs.
This is a wonderful tool for me in a Social Sciences
department where the Professors are always designing surveys to
gather data. I can deplay a web-based survey in a few hours, and,
with your help and many hours poring over manuals, I have the first
example working in ColdFusion. And, incidentally, the ColdFusion
version is way tidier, more compact, and more readable than the ASP
version.
Dan, I'll be happy to answer other peoples' questions as soon
as I am more confident in my knowlege of ColdFusion!
-Richard
Richard Hopley
Research Associate
Department of Social Science and Health Policy
Wake Forest University Medical School
Winston-Salem, NC -
I read ALL the textbook
MACROMEDIA CF, 2002 course.com
Well to run a <cfquery> I must include a "password" attribute, etc
except I have a local server ? yes / no
May use/include a file dbinfo.cfm with all my passwords etc , and use
these passwords as variables in <cfquery>,...etc ? this is more secure ?
I must include vars in <cfscript> tag OR many <cfset> tags ?
If I had
<cfscript>
password='gf56SDRPO999';
</cfscript>
HOW TO INCLUDE THIS VAR IN <cfquery password=#password# ...> this is correct ?Your question is unclear to me, but if you just want to verify your syntax is legal, then YES. You can easily set a value in a variable with <cfscript> and then later use that variable in a <cftag...> like you showed.
But I would argue there is little additional security in using passwords in code like this between setting the password and using it directly in the tag. There may be reusability and maintainability advantages, but little advantage to security. -
Newbie question about component and UDF usage.
This will be the 1st time I'm coding a component and UDF. I
kind of understand the concept but not sure about how to write it
in detail.Such as passing the parameter, etc.
I'm starting to write a user login, verifying users before
allowing them to enter into the app.
So I have 2 fields in my login form, Login and password.
Upon submitting this form, on the actionpage.cfm I'm calling
a component. This is how I call the component:
<CFINVOKE Component="cfc/loginaction"
Method="AuthentiCateUser" ReturnVariable="UserInfo">
Then in my Component I have the following:
<CFCOMPONENT>
<CFFUNCTION Name="AuthentiCateUser" RETURNTYPE="Query"
hint="Use for user login">
<CFARGUMENT Name="login" Type="Structure"
Required="true">
<CFARGUMENT Name="password" Type="Structure"
Required="true">
<!--- checking user authentication --->
<CFQUERY NAME="Authenticate" DATASOURCE="sendfast">
SELECT * FROM tblcustomer WHERE Login = '#Login#' AND
Password = '#Password#'
</CFQUERY>
<CFRETURN AuthentiCateUser>
</CFFUNCTION>
</CFCOMPONENT>
When I run this code, I got error, it said :
The parameter LOGIN to function AuthentiCateUser is required
but was not passed in.
The error occurred in
C:\CFusionMX\wwwroot\KDt_Mod\userloginaction.cfm: line 18
16 : <CFSET
UserLoginInfo["Password"]="#Form.Password#"> 17 : 18 :
<CFINVOKE Component="cfc/loginaction" Method="AuthentiCateUser"
ReturnVariable="UserInfo">
19 :
My question is:
What should I do in order to pass #Form.Login# and
#Form.Password# to my UDF within my component?
I'm using CFMX 6 and Micrisift SQL 8I've applied cfinvokeargument and my login and password were
passed to my component.
But I'm facing new problem: Where should I write my
authentication? should I write user authentication within my
component or
loginaction.cfm (the calling template)
What I mean by authentication is something like this:
<CFIF #Authenticate.RecordCount# IS NOT 0>
<cfset session.CustomerID
="#Authenticate.customerid#">
<cfset session.Name ="#Authenticate.Name#">
<CFCOOKIE NAME="UserLoginIn"
VALUE="12345_pn#Authenticate.customerid#">
<cflocation url="index.cfm?loc=home">
<CFELSE>
<script language="JavaScript">
alert("Username/password is not found, plese try again");
history.go(-1);
</script>
<cfabort>
</CFIF>
If I keep this code in my loginaction.cfm what is returned
from my function is not recognized by the component, the error said
Authenticate.RecordCount is not recognized.
Also I'm still confuse with what should I put in the
RETURNTYPE. If I put query, it gave me error, also, what is
returned by CFRETURN.
This is my component:
<CFCOMPONENT>
<CFFUNCTION Name="AuthentiCateUser" RETURNTYPE="Query"
hint="Use for user login">
<CFARGUMENT Name="login" Type="Structure"
Required="true">
<CFARGUMENT Name="password" Type="Structure"
Required="true">
<!--- checking user authentication --->
<CFQUERY NAME="Authenticate" DATASOURCE="sendfast">
SELECT * FROM tblcustomer WHERE Login = '#Login#' AND
Password = '#Password#'
</CFQUERY>
<CFRETURN AuthentiCateUser>
</CFFUNCTION>
</CFCOMPONENT> -
I have a recordset that looks like the following:
Gender City Country
Male New York USA
Male New York USA
Female Boston USA
Female Quebec CAN
Female Quebec CAN
I'm trying to output counts of all this data so that the
output should look like:
Male 2
Female 3
New York 2
Boston 1
Quebec 2
USA 3
CAN 2
Can anyone show me the best/most efficient way of doing this?
Also the query pulls 3 or 4 additional columns that I need counts
on if that makes a difference.
Many thanks in advance!EDIT: Figured it out, thanks again Dan! /EDIT
Thanks Dan. That helps a ton for queries with known finite
column values. I use the following to get recordcounts of male vs.
female:
<cfquery name="masterquery" datasource="#dsn#">
select * from demographics
</cfquery>
<cfquery name="allMales" dbtype="query">
select * from masterquerywhere gender = 'Male'
</cfquery>
<cfquery name="allFemales" dbtype="query">
select * from masterquerywhere gender = 'Female'
</cfquery>
Female:
<cfoutput>#allFemales.recordcount#</cfoutput>
Male: <cfoutput>#allMales.recordcount#</cfoutput>
This returns just what I need it to. My followup question is
how to do this on a column like City which may contain hundreds of
different values? In the male / female example, it's no problem to
create 2 query of queries. However, I couldn't possibly write a
seperate query for every possible city.
I know there has to be some looping here but I'm just not
sure how to do this. Any thoughts?
Again many thanks in advance!
Incidentally, I was dramatically overanalyzing the loop code.
Turns out it's far simpler than I had thought:
<cfquery name="demoCityList" dbtype="query">
select distinct (city) from GetFullDemographicInfo
</cfquery>
<cfloop index="i" from="1"
to="#demoRegionList.recordcount#">
<cfquery name="demoRegionTotal" dbtype="query">
select count(city) as cityTotal from GetFullDemographicInfo
where city = '#demoRegionList.city
</cfquery>
<cfoutput>#demoRegionList.city#</cfoutput>
<cfoutput>#demoRegionTotal.cityTotal#</cfoutput><br/>
</cfloop> -
Various Query`s in the same CFQuery
in SQL i have many query`s in the same statement of the sql
for example:
select * from peticion2007 order by anio,numero;
select * from peticion2006 order by anio,numero
and the result are two tables with information at the
peticion2007 and peticion2006
the questions are how do it this in CF?
i have this program:
<cfquery name="q01" datasource="peticion">
select * from peticion2007 order by anio,numero;
select * from peticion2006 order by anio,numero
</cfquery>
<html>
<body>
<table>
<cfoutput query="q01">
<tr>
<td>#q01.anio#</td>
<td>#q01.numero#</td>
</tr>
</cfoutput>
</table>
</body>
</html>
this program are runing but only the first query is show, at
the table peticion 2007, the table peticion2006 is not
showing¡¡
can you help mequote:
Originally posted by:
venon69
how can use the cfstoredproc?
are you have any example?
the problem are my server is very small and the number of
register are more of 15 millions of register
the find is very slow, and the backup is very dificultsly
The docs for cfstoredproc have an example. If you are using a
low-grade database like Microsoft Access, you would use
cfstoredproc to call a saved query instead. See
http://cfdj.sys-con.com/read/41539.htm
for example.
15 million rows is nothing for a proper database if decent
indexes are set up. Even Microsoft Access could handle it (although
not very well). -
I was wondering if I could put the following requirement into a single member formula:I need to calculate the average value of a level 0 time member of the descendants of the current member.For example, If I select Qtr1, I need the average of Accounts Balance for the days (level 0) that make up Qtr1. If I select Qtr2, I need the average Accounts Balance for the days of Qtr2.I tried the following formula, but it wasn't right:@AVGRANGE(SKIPBOTH, "ACCOUNT BALANCE",@LEVMBRS(TIME, @DESCENDANTS(@CURRMBR(TIME)))For now, I'm using IF's, i.e., IF Qtr1, Average the range of days 1-90, IF Qtr2, averager the range of days 91-120, etc. Just wondering if there's another way to do it.Thanks in Advance!!
Your question wasn't very clear, but if you only want to sort
them by the count in descending order, just ORDER BY 1 DESC.
<cfquery name="GetEventCount"
datasource="JasperCountyDB">
SELECT COUNT(AG_ID) as EventCount, TYCOD, TYP_ENG, CURENT
FROM aeven
WHERE AG_ID = '#Session.InquiryAgencyCode#'
AND CURENT = 'T'
AND CDTS LIKE '#EventReportDate#'
GROUP BY AG_ID, TYCOD, TYP_ENG, CURENT
ORDER BY 1 DESC
</cfquery>
Phil -
I am doing a 9-1-1 reporting system. I am selecting calls by
Agency and type of call for a given month. That works fine, but I
need them printed in desending sequence by number call far a call
type. Don't see anyway to accomplish that with one query.
Is that a way? If not, the second part of this question is
that I have not created a table using SQL. I need 3 fields, Field_A
is Text (9 positions); Field_B is Text (40 Positions) and the last
is my summarized count from the query. How do I create a Table to
support this function?
Query
<cfquery name="GetEventCount"
datasource="JasperCountyDB">
select count(AG_ID) as EventCount, TYCOD, TYP_ENG, CURENT
from aeven
where ((AG_ID = '#Session.InquiryAgencyCode#')
AND (CURENT = 'T') AND (CDTS LIKE '#EventReportDate#'))
group by AG_ID, TYCOD, TYP_ENG, CURENT
</cfquery>
Thanks for any guideance that you can provide.
RonYour question wasn't very clear, but if you only want to sort
them by the count in descending order, just ORDER BY 1 DESC.
<cfquery name="GetEventCount"
datasource="JasperCountyDB">
SELECT COUNT(AG_ID) as EventCount, TYCOD, TYP_ENG, CURENT
FROM aeven
WHERE AG_ID = '#Session.InquiryAgencyCode#'
AND CURENT = 'T'
AND CDTS LIKE '#EventReportDate#'
GROUP BY AG_ID, TYCOD, TYP_ENG, CURENT
ORDER BY 1 DESC
</cfquery>
Phil -
Proper DB Access usgin CFQUERY?
Your worst nightmare - after 18 months of code development
with 2 weeks left before BETA. My site experienced a SQL Injection
Attack 2 days ago. A URL pointing to China which trys to call a js
script. I am a self taught CF user who has coded many sites never
thinking it would happen to me. I have already read the many
threads on using CFPARAM to bind the DB types. So I have to go back
through hundreds of CFML files to do that. Now that I am paranoid I
am trying to figure out what else I can do on the SQL 2005 Server
side. I have always used my db_owner login password in CFQUERY to
make the connection, which is apparently a no-no. I can't find any
best practices online: 1) Should you use the username/password in
CFQUERY or just specify it in CF Admin? However, I thought if you
do that, then any call can be made directly to the DB. I heard you
should store the DB credentials in the application file encoded and
then call them as a new variable so they're not in plain text in
your CFQUERY? 2) If I setup a new role in SQL 2005, do people use
standard or the application role? 3) I fear I will keep getting hit
by the SQL injection code until everything is fixed. Not knowing
the extent of the damage how should I lock down the DB tables using
Enterprise Manager in SQL 2005? As you can see I have tons of
questions, and tons of work now that my site is targeted I know
little about DB security.brwright wrote:
> Your worst nightmare - after 18 months of code
development with 2 weeks left
> before BETA. My site experienced a SQL Injection Attack
2 days ago. A URL
> pointing to China which trys to call a js script. I am a
self taught CF user
> who has coded many sites never thinking it would happen
to me. I have already
> read the many threads on using CFPARAM to bind the DB
types.
Not cfparam, cfqueryparam.
> So I have to go
> back through hundreds of CFML files to do that. Now that
I am paranoid I am
> trying to figure out what else I can do on the SQL 2005
Server side. I have
> always used my db_owner login password in CFQUERY to
make the connection, which
> is apparently a no-no. I can't find any best practices
online: 1) Should you
> use the username/password in CFQUERY or just specify it
in CF Admin? However, I
> thought if you do that, then any call can be made
directly to the DB. I heard
> you should store the DB credentials in the application
file encoded and then
> call them as a new variable so they're not in plain text
in your CFQUERY?
There is no clear consensus on the usage of a u/p in all
queries versus
storing the u/p in the CF Administrator. However, hardcoding
the u/p in
each cfquery statement is bad. You should create variables
for the
username and password and use those variables in your
queries. (Just
imagine in how many places you have to change the code if you
have a
security policy where you have to change all passwords every
3 months.)
> 2) If
> I setup a new role in SQL 2005, do people use standard
or the application role?
Depends. Typically dbreader/dbwriter is used for applications
that do
not use stored procedures.
> 3) I fear I will keep getting hit by the SQL injection
code until everything is
> fixed. Not knowing the extent of the damage how should I
lock down the DB
> tables using Enterprise Manager in SQL 2005?
Always.
Jochem
Jochem van Dieten
Adobe Community Expert for ColdFusion -
ColdFusion.Ajax.submitForm ResultHandler Question
I am developing an CF Ajax based solution in which I use
ColdFusion.Ajax.submitForm to pass form values to a CFC for
processing via Java Script. My question is related to the Java
Script resultHandler and whether or not there is an easy way to
return the results from the CFC to handler.
My Java Script looks like this...
function InsertRec() {
ColdFusion.Ajax.submitForm('MyForm',
'service.cfc?method=InsertRec', resultInsertHandler,
resultErrorHandler);
My CFC looks like this.. (condensed)
<cffunction name="insertRec" access="remote" output="no"
returntype="numeric">
<cfargument name="NAME">
<cfargument name="Phone">
<cfquery name="recInsert" datasource="#request.DS#">
<cfset NEW_NUMBER = updatedNum( )> <-- Getting new #
from another table via CFC
INSERT INTO MYTABLE
(NUMBER, NAME, PHONE)
Values (' #NEW_NUMBER# ' , ' #ARGUMENTS.NAME# ' , '
#ARGUMENTS.PHONE# ' )
</cfquery>
<cfreturn NEW_NUMBER>
</cffunction>
What I'm trying to do is return the value of NEW_NUMBER from
the CFC back to resultInsertHandler so I can use it in a Java
Script alert msg. Any ideas or thoughts would be greatly
appreciated.
Regards
Martin FranklinMMFranklin wrote:
> What I'm trying to do is return the value of NEW_NUMBER
from the CFC back to
> resultInsertHandler so I can use it in a Java Script
alert msg. Any ideas or
> thoughts would be greatly appreciated.
Something like this I would presume.
function resultInsertHandler(returnMsg)
alert(returnMsg); -
Ok, I'm working on my first CFC, and having some problems.
The code I have
so far is:
<cfcomponent displayname="duplicate" hint="Duplicates
local club
tournaments">
<!--- This function retrieves all customers from the
database --->
<cffunction name="getinfo"
hint="Gets all tournament info from the database">
<cfquery name="DuplicateTournamentList"
datasource="SalleBoise">
select * from clubtournaments
where TournID=#session.tid#
</cfquery>
<cfset NewEventName=DuplicateTournamentList.TournName>
<cfset NewEventDesc=DuplicateTournamentList.TournDesc>
<cfset
NewDateTime=dateadd("m",2,dateformat(TournDateTime,"mm/dd/yyyy"))>
<cfset
NewTournFoil=DuplicateTournamentList.TournFoilEvent>
<cfset
NewTournEpee=DuplicateTournamentList.TournEpeeEvent>
<cfset NewType=DuplicateTournamentList.EventType>
<cfset
NewDuplicate=DuplicateTournamentList.TournDuplicated>
<cfquery name="NewTourn" datasource="SalleBoise">
insert into clubtournaments
(TournName,TournDesc,TournFoilEvent,TournEpeeEvent,EventType,TournDateTime,TournDuplicate d)
values
(#NewEventName#,#NewEventDesc#,#NewTournFoil#,#NewTournEpee#,#NewType#,#NewDateTime#,#NewD uplicate#)
</cfquery>
<cfquery name="UpdateOldTourn" datasource="SalleBoise">
update clubtournaments
set TournDuplicated=1
where TournID=#session.tid#
</cfquery>
</cffunction>
</cfcomponent>
And I'm calling it with:
<cfinvoke component="duplicate.cfc" method="getinfo">
And I'm getting:
Error Occurred While Processing Request
Could not find the ColdFusion Component or Interface
duplicate.cfc.
Ensure that the name is correct and that the component or
interface exists.The 1 question I have with your code that is different than
mine is the
query. Mine, I had hoped would take the info from the
previous event,
and add a number of months to it before adding it into the
table.
It looks like yours simple duplicates the event without
changing that
date, correct?
Azadi wrote:
> first, rtfm about <cfinvoke> tag. the component
attribute needs a
> dot-delimited path to your cfc, i.e. if your cfc is
stored in a
> components folder under web root and your calling
template is also in
> the webroot: component="components.duplicate"
>
> then, it is not a good practice to access outside
variables from within
> the cfc - in your case you are accessing session vars.
you better pass
> them in to your cfc as arguments when you invoke it and
have
> <cfargument> tags in your function that accept
them (see code at the bottom)
>
> <cfinvoke component="components.duplicate"
method="getinfo"
> tid="#session.tid">
>
> or
>
> <cfinvoke component="components.duplicate"
method="getinfo">
> <cfinvokeargument name="tid"
value="#session.tid#">
> </cfinvoke>
>
> then, variable scoping - always scope any cfc vars with
var: <cfset var
> somevar = something>. this will help you avoid
variables confusion when
> your calling page has vars with same names.
>
> then, even inside cfc, you should always use
<cfqueryparam> tags in your
> queries.
>
> as for your queries - the 3 of them can be combined
easily into one.
>
> so your function in the end can look something like:
> [note: query syntax is db-specific; check your db for
correct syntax to use]
>
> <cffunction name="getinfo"
> hint="Gets all tournament info from the database"
returntype="boolean"
> output="no">
> <cfargument name="tid" required="yes"
type="numeric">
> <cfset var DuplicateTournamentList = "">
> <cfset var result = true>
> <cftry>
> <cfquery name="DuplicateTournamentList"
datasource="SalleBoise">
> INSERT INTO clubtournaments
> (TournName, TournDesc, TournFoilEvent, TournEpeeEvent,
EventType,
> TournDateTime, TournDuplicated)
> SELECT TournName, TournDesc, TournFoilEvent,
TournEpeeEvent, EventType,
> TournDateTime, 1 AS TournDuplicated
> FROM clubtournaments
> WHERE TournID = <cfqueryparam
cfsqltype="cf_sql_integer"
> value="#arguments.tid#">
> </cfquery>
> <cfcatch type="any">
> <cfset result = false>
> </cfcatch>
> </cftry>
> <cfreturn result />
> </cffunction>
>
> and your cfinvoke something like the examples above.
>
> hth
>
>
> Azadi Saryev
> Sabai-dee.com
>
http://www.sabai-dee.com/ -
Have a set of questions in which a person answers...
It works fine looping thru the questions... And inserting...
Problem occurs - when I want them to go back and answer the ones that were 'No'...
So it might only be 3 questions instead of 10...
So that is where my loop errors...
As it is based on a Question ID
Yes<br><cfinput type="Radio" name="answer_2" value="Yes" required="yes">
Yes<br><cfinput type="Radio" name="answer_4" value="Yes" required="yes">
Yes<br><cfinput type="Radio" name="answer_5" value="Yes" required="yes">
An example of what is being sent above...
So 2, 4, 5 are the questions...
My loop goes through 3 of them which is fine...
But mismatches - thinking it should be 1,2,3 etc..
Yes<br><cfinput type="Radio" name="answer_1" value="Yes" required="yes">
Yes<br><cfinput type="Radio" name="answer_2" value="Yes" required="yes">
Yes<br><cfinput type="Radio" name="answer_3" value="Yes" required="yes">
So not sure what to do to code it as looping through the actual answer numbers...
Some code below...
<cfloop from="1" to="#q#" index="n"> ---> q is a record count of wrong answers
<cfoutput>
<!--- first we set up field names to match what the form should be passing. --->
<cfset newqid = "#variables.n#"> #newqid# (test output)
<cfset newanswer = "answer_"&#variables.n#> #newanswer# (test output)
<cfset newnotes1 = "notes1_"&#variables.n#> #newnotes1# (test output)
<cfset newnotes2 = "notes2_"&#variables.n#> #newnotes2# (test output)
<cfset newcnote = "compliancenote_"&#variables.n#> #newcnote#(test output)
<br>
<!--- then we get whatever values are in those field names and set them as vars --->
<cfset qid = "#Evaluate(variables.newqid)#"> #qid# (test output)
<cfset answer = "#Evaluate(variables.newanswer)#"> #answer#
<cfset notes1 = "#Evaluate(variables.newnotes1)#"> #notes1#
<cfset notes2 = "#Evaluate(variables.newnotes2)#"> #notes2#
<cfset compliancenote = "#Evaluate(variables.newcnote)#"> #compliancenote#
<cfset inspid = "#Evaluate(inspid)#"> #inspid#
<cfset busid = "#Evaluate(busid)#"> #busid#
<cfquery name="insert" datasource="fpb">
INSERT INTO answer (qid, answer, inspid, busid, notes1, notes2, compliancenote)
VALUES (#qid#, '#answer#', #inspid#, #busid#, '#notes1#', '#notes2#', '#compliancenote#');
</cfquery>
</cfoutput>
</cfloop>
This all works fine when just inserting fresh from start say 10 questions...
Which can be yes no etc...
Thanx for any help...
MerleDamn...
It is late at night... Rum and EggNog...
I can't seem to set this output...
This works...
<cfoutput query="reinspect">
#qid#,
</cfoutput>
Goes ---> 2,5,8,9, (example - comma is stuck on end)
My problem is probably below...
<cfset numbers = "
<cfoutput query="reinspect">
#qid#,
</cfoutput> "> -
I have a .cfm template that is used to render a handful of
pages of my website. Each page is a department, for example, like
"Arts & Entertainment", "Health", "Finance", and so on. On each
of these pages (rendered by this same template) there is a common
element... a list of our top ten articles. I have used the
"cachedwithin" feature to cache the query for a 3-hour period.
My question is this...
Since it is a single template generating these department
pages, the "top articles" query is exactly the same in terms of
query name, datasource... only the SQL statement (which uses a
"WHERE department_id = X" statement) is different. Let's say I have
ten departments rendered by this template... should it be caching
all ten queries, regardless of the names being the same?Hopefully you only have one cfquery tag and it is located in
the .cfm template and you are using a variable in your where
clause. If not, you are not being efficient with your code.
If you do have just one cfquery tag, and you have a
cachedwithin attribute, cold fusion will cache a query each time
your variable changes. -
I'm trying to create a page that displays the results of a query, but will allow you to filter them by date, name, etc. I'm relatively new to this concept, but reading a bit online I found some examples that did what I'm trying to do. I have a few questions and a problem though, if someone is willing to provide a bit of guidance. If it matters, I'm using cf9.
First, can you use a <cfdiv bind to submit multiple url parameters? If so, do I just use a semicolon to separate them like this:
<cfdiv bind="url:mypage.cfm?param1={value1};param2={value2}" />
Second, if you can use this functionality, what's the best way to send dates as url parameters? URLEncodedFormat() and then URLDecode()? All the examples of those tags surround them with # to indicate variables, but since you don't use that notation in a cfdiv bind, do I just put the whole thing inside the {} like this (and then use URLDecode(mydate) on the action page):
<cfdiv bind="url:mypage.cfm?date1={URLEncodedFormat(mydate)} />
Third, I'm having trouble getting the <cfdiv bind to display at all. I have an action page set up (mypage.cfm) that loads fine in a browser, but when I try to add it to another page like this, it doesn't work:
<cfdiv bind="url:mypage.cfm" />
I'm assuming this is because I'm not submitting any parameters on this page to be processed on mypage.cfm, but I don't know if that's true. I'm trying to get the div to display first, then add the dynamic form to filter the results, but maybe it doesn't work that way?
Thanks for any help!
JeremyThank you, I was able to get it mostly working. There was an issue with the server on my system so I had to re-install Coldfusion. It dawned on me that I had cleaned up some files that I was no longer using and might have accidentally gotten rid of something important.
So it's definitely better now. I can change the dates so that I can display records that fall within those date parameters. What I'm trying to do now is be able to sort the records, and I'm having trouble with that. Right now I have a select menu named "sort" with a bunch of values that reference elements in the table: Last Name (Lname), Date Submitted (Reptime), and Date of Absence (Absence_Date). Then in my sql I have "ORDER BY <cfparam value="#url.sort# cfsqltype="cf_sql_varchar">. I don't get any errors or anything, I just don't get any changes to the displayed data. Here's my sql, the commented parts are not in the file, I added those for explanation here:
<!--- There are two radio buttons to toggle between viewing all records and viewing the selected records based on the date parameters. This sets the start and end dates when view all is selected --->
<cfif IsDefined("url.viewAll") AND #url.viewAll# EQ "yes">
<cfset startDate="01/01/2012">
<cfset endDate="12/12/2020">
<cfelse>
<!--- This sets the start and end dates based on the items in those fields if view all is not selected, and sets the dates to the view all dates if the date entry fields are empty --->
<cfif IsDefined("url.startDate") AND #url.startDate# NEQ "">
<cfset startDate="#url.startDate#">
<cfelse>
<cfset startDate="01/01/2012">
</cfif>
<cfif IsDefined("url.endDate") AND #url.endDate# NEQ "">
<cfset endDate="#url.endDate#">
<cfelse>
<cfset endDate="12/12/2020">
</cfif>
</cfif>
<!--- Defines the url.sort parameter and sets the default in the event no selection is made on the page. --->
<cfparam name="url.sort" default="Absence_Date">
<!--- And my query. Pretty self-explanatory, but the ORDER BY portion isn't working. Records are displayed in the order they appear in the database, which is the submit time (Reptime) --->
<cfquery name="absences" datasource="ctband">
SELECT *
FROM Absences
WHERE Absence_Date > <cfqueryparam value="#startDate#" cfsqltype="cf_sql_varchar"> AND Absence_Date < <cfqueryparam value="#endDate#" cfsqltype="cf_sql_varchar">
ORDER BY <cfqueryparam value="#url.sort#" cfsqltype="cf_sql_varchar">
</cfquery>
Maybe you are looking for
-
Hi all. 2 weeks ago my new 20" Nvidia iMac was delivered. I was replacing a Rev A G5 17" iMac. I noticed that the noise the machine makes whilst quieter is not 'really' quiet like my dad's 24". The HDD fan speed is around 1600 and the noise does appe
-
View objects referencing the same entity
The behaviour occurs in every version of jdeveloper ADF BC i have tried so far (10g, 11g). I have 2 updatable view objects referencing the same entity object. When i create a new record using the first view object and before commiting the data to the
-
Hi, My apologies if this isn't in the right section. I currently inherited a stored procedure to work on which is calling sp_send_dbmail. The sp executes without any errors and I'm able to see entries in sysmail_allitems as well as receive emails. Th
-
11.5.10 on Win2K
Hi, I have installed 11.5.10 on Win2K. It has the DB tier and Forms tier on different nodes. After the installation, all work well for a few hours and then for no apparent reason I can no longer access Apps. I just get the following message... Intern
-
Decode vs (parseInt or valueOf) ?
What's the difference between the decode and parseInt methods of the Integer class? Josh