请考虑以下代码:
在此代码中,将要求用户从两个选项中选择一个日期范围,然后单击“应用”按钮,以便可以在Web浏览器上显示所选日期范围的结果。
我想知道我应该如何进行。请对此加以说明。
2)如何确保可以启用使用“下载CSV”选项下载数据的选项?
请让我知道需要什么更改。任何帮助,将不胜感激。
<body>
<cfparam name="Form.startdate" default="#dateformat(now()-5, 'mm/dd/yyyy')#">
<cfparam name="Form.enddate" default="#dateformat(now()-1, 'mm/dd/yyyy')#">
<cfparam name="Form.selectdate" default="#dateformat(now(), 'mm/dd/yyyy')#">
<!--- <cfquery datasource = "xx.xx.x.x" name="qCheck">
SELECT *
FROM mydatabase
ORDER BY DTSId_bi LIMIT 10;
</cfquery>
--->
<cfquery datasource = "xx.xx.x.x" name="qDatabase">
SELECT (SELECT count(*) FROM mydatabase) AS TOTAL_CONNECTIONS,
(SELECT count(*)FROM mydatabase WHERE event_vc = "open") AS OPEN_CONNECTIONS,
(SELECT count(*)FROM mydatabase WHERE event_vc = "BOUNCE") AS BOUNCE_CONNECTIONS,
(SELECT count(*) from mydatabase where event_vc = "DEFERRED") AS DEFERRED_CONNECTIONS,
(SELECT count(*) from mydatabase where event_vc = "DELIVERED") AS DELIVERED_CONNECTIONS,
(SELECT count(*) from mydatabase where event_vc = "DROPPED") AS DROPPED_CONNECTIONS,
(SELECT count(*) from mydatabase where event_vc = "PROCESSED") AS PROCESSED_CONNECTIONS,
(ROUND((SELECT OPEN_CONNECTIONS / (TOTAL_CONNECTIONS))*100)) AS "OPEN",
(ROUND((SELECT BOUNCE_CONNECTIONS / (TOTAL_CONNECTIONS))*100)) AS "BOUNCE" ,
(ROUND((SELECT DEFERRED_CONNECTIONS / (TOTAL_CONNECTIONS))*100)) AS "DEFERRED",
(ROUND((SELECT DELIVERED_CONNECTIONS / (TOTAL_CONNECTIONS))*100)) AS "DELIVERED",
(ROUND((SELECT DROPPED_CONNECTIONS / (TOTAL_CONNECTIONS))*100)) AS "DROPPED",
(ROUND((SELECT PROCESSED_CONNECTIONS / (TOTAL_CONNECTIONS))*100)) AS "PROCESSED";
</cfquery>
<cfform format="flash" preloader ="false">
<!--- Arranging the two buttons adjacent to each other using cfformgroup tag --->
<cfformgroup type="horizontal">
<p> </p>
<p> </p>
<p>
<cfinput type="dateField" name="startdate" label="Start Date" width="100" value="#Form.startdate#">
<cfinput type="dateField" name="enddate" label="End Date" width="100" value="#Form.enddate#">
<cfinput name="submit" type="submit" value = "Apply">
<cfinput name="cancel" type="submit" value="Download CSV">
</p>
</cfformgroup>
<!--- For Horizontal Line --->
<cfformitem type = "hrule" style=""></cfformitem>
</cfform>
<cfchart
format="png"
chartwidth="500"
chartheight="500"
scalefrom="0"
scaleto="1200000"
title="Email Reporting "
pieslicestyle="solid">
<cfchartseries type="line"
>
<cfchartdata item="% OPEN" value="#qDatabase.OPEN#">
<cfchartdata item="% BOUNCE" value="#qDatabase.BOUNCE#">
<cfchartdata item="% DEFERRED" value="#qDatabase.DEFERRED#">
<cfchartdata item="% DELIVERED" value="#qDatabase.DELIVERED#">
<cfchartdata item="% DROPPED" value="#qDatabase.DROPPED#">
<cfchartdata item="% PROCESSED" value="#qDatabase.PROCESSED#">
</cfchartseries>
</cfchart>
</body>
最佳答案
如果我是您,我真的会考虑重新处理qDatabase查询,这效率很低!就下载csv而言,最好的方法是将文件写入需要清除的临时区域,以免填满HD。我将帮助编写文件,但不会帮助您进行清理。您可以执行以下操作:
<cfscript>
var tl ='';
var nl = (Chr( 13 ) & Chr( 10 ));
var fileContent = createObject("java","java.lang.StringBuffer").init();
var counter =1;
fileContent.append( 'OPEN,BOUNCE,DEFERRED,DELIVERED, etc');
fileContent.append(nl);
for(i=1;i<=qDatabase.recordCount;i=i+1){
tl = qDatabase.OPEN&','qDatabase.BOUNCE&','qDatabase.DEFERRED&','qDatabase.DELIVERED&',' etc;
fileContent.append(tl);
fileContent.append(nl);
}
</cfscript>
<cffile action="write" file="#absoluteFilePathAndName#" mode="775" output="#fileContent.toString()#"/>
<a href="#realtiveFilePathAndName#>Download</a>
每当有人点击该页面时,这都会将一个csv文件写入绝对路径,因此您需要围绕它的一些条件逻辑来防止这种情况的发生。
总体而言,您需要重新审视所提供的代码并重新考虑您在做什么,但是一旦执行此代码,您将开始使用它,这不是您的最终解决方案。
关于mysql - 在ColdFusion 8中玩弄日期范围,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17559071/