简体   繁体   English

将 Coldfusion 查询结果传递给 Form

[英]Passing Coldfusion query result to Form

I have two Coldfusion templates ( getdata.cfm and generate.cfm ).我有两个 Coldfusion 模板( getdata.cfmgenerate.cfm )。 The first template getdata.cfm will retrieve from a database with a query, in addition to other tasks.除其他任务外,第一个模板getdata.cfm将使用查询从数据库中检索。 It will retrieve exactly 16 rows of data and each row will have 8 fields.它将准确检索 16 行数据,每行将有 8 个字段。 Such as this:比如这样:

<cfquery datasource="xyz name="lista">
SELECT n1,n2,n3,n4,n5,n6,n7,n8
FROM atable
WHERE product = "abc"
ORDER BY date DESC LIMIT 16
</cfquery>

The second template will generate some random numbers and compare them against these 16 rows.第二个模板将生成一些随机数并将它们与这 16 行进行比较。 There is a Refresh button on the second template to regenerate the numbers.第二个模板上有一个刷新按钮来重新生成数字。 This is how I would like it to work.这就是我希望它工作的方式。

However, right now the only way for it to work is having the database <cfquery> in the second template, generate.cfm That means every time I press Refresh, it will access the database, retrieve the same 16 rows every time, and generate the random numbers.但是,现在唯一的方法是在第二个模板中使用数据库<cfquery>generate.cfm这意味着每次我按刷新时,它都会访问数据库,每次检索相同的 16 行,并生成随机数。 This is not ideal.这并不理想。 Because the 16 rows are the same, it makes no sense to retrieve them every time a new set of random numbers get generated.因为这 16 行是相同的,所以每次生成一组新的随机数时都检索它们是没有意义的。 It would be best to get them once, in the first template and somehow pass them to the second template.最好在第一个模板中获取它们一次,然后以某种方式将它们传递给第二个模板。 The 16 sets of numbers will need to be displayed on the screen at all times.这 16 组数字需要始终显示在屏幕上。 The matched and unmatched numbers need to be shown.需要显示匹配和不匹配的数字。

How can I pass the whole query result from the first template to the second one without having to pass the 16 records as 16 lists via the form as form fields?如何将整个查询结果从第一个模板传递到第二个模板,而不必通过表单将 16 个记录作为 16 个列表作为表单字段传递? Is this even possible?这甚至可能吗? Thanks in advance.提前致谢。

  • Generate a set of random numbers.生成一组随机数。
  • Compare those numbers against a static set of data.将这些数字与 static 数据集进行比较。
  • Repeat.重复。

Do you need to do the comparison in the application (CFML) code?您是否需要在应用程序 (CFML) 代码中进行比较? Can you generate the set of random numbers and send them to the DB as part of the query in a single request?您能否在单个请求中生成一组随机数并将它们作为查询的一部分发送到数据库? That way, you get the records from the DB that match your set of numbers and not all 16.这样,您可以从数据库中获取与您的数字集匹配的记录,而不是全部 16 个。

Then every refresh would send the new set of random numbers to the DB, returning only the relevant data.然后每次刷新都会将新的随机数集发送到数据库,只返回相关数据。

Alternately, you can use cfquery with the cachedWithin attribute in order to store the results of the query into memory for a specific amount of time while refreshing your random set of numbers.或者,您可以将cfquerycachedWithin属性一起使用,以便在刷新随机数字集的同时将查询结果存储到 memory 特定时间。

https://cfdocs.org/cfquery https://cfdocs.org/cfquery

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM