Coldfusion结构体语法和查询数据
到目前为止,我基本上只使用冷融合进行查询,之前从未需要过结构或任何对象表示法。我正在使用的服务器没有打开调试,只是出现“500-内部服务器错误”。所以我不明白为什么我的代码不起作用,遗憾的是我无法打开调试。
通过注释块的反复试验,我注意到错误发生在我的结构行中,并将该结构添加到我的数组中。从我读到的 CF 文档来看,我没有看到任何语法错误,但如果我有任何错误的逻辑或可能出现什么问题,我们将不胜感激。
<cfset dataArray = []>
<cfset i = 0>
<cfloop query="getMembers">
<cfquery name="getmaps" datasource=“a" dbtype="odbc">
SELECT member_id, mlong, mlat
FROM maps
WHERE member_id = '#getMembers.MemberID#'
</cfquery>
<cfif getmaps.recordcount eq 1>
<!--- temp structure to insert into array --->
<cfset dataTemp = {
memberID = getMemebers.memberID,
name = getMemebers.MemberName,
long = getmaps.mlong,
lat = getmaps.mlat
}>
<cfset dataArray[i] = dataTemp>
<cfset i++>
</cfif>
</cfloop>
I’ve mostly only used coldfusion for queries before never needed structs or any object notation until now. The server I am working on doesn’t have debugging turned on just a “500- internal server error.” so I am unable to see why my code is not working and sadly I do not have the ability to turn debugging on.
By trial and error with commenting blocks out I’ve noticed the errors are occurring in my struct line, and adding the struct to my array. From what I’ve read of the CF documentation I do not see any syntax errors but any help would be much appreciated as to if I have any bad logic or what could be wrong.
<cfset dataArray = []>
<cfset i = 0>
<cfloop query="getMembers">
<cfquery name="getmaps" datasource=“a" dbtype="odbc">
SELECT member_id, mlong, mlat
FROM maps
WHERE member_id = '#getMembers.MemberID#'
</cfquery>
<cfif getmaps.recordcount eq 1>
<!--- temp structure to insert into array --->
<cfset dataTemp = {
memberID = getMemebers.memberID,
name = getMemebers.MemberName,
long = getmaps.mlong,
lat = getmaps.mlat
}>
<cfset dataArray[i] = dataTemp>
<cfset i++>
</cfif>
</cfloop>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
除了 Shawn 的评论之外,我相信您在从 0 而不是 1 开始数组索引时会遇到问题。Coldfusion 从 1 开始数组索引。
编辑更多建议:
I addition to Shawn's comment, I believe you'll have a problem with starting your array index at 0, rather than 1. Coldfusion begins array indices at 1.
edit Some more suggestions:
您应该考虑将两个查询合并为一个查询。
当您只需要一个查询时,当前方法可能会生成数千个查询!
每当您发现自己循环查询并调用其他查询时,最好修改原始查询并避免对数据库服务器造成影响。
为了将数据放入结构数组中,杰克的答案效果很好。
You should consider combining the two queries into one query.
The current method could potentially generate thousands of queries when you only need one!
Anytime you find yourself looping over a query and calling other queries, it is a good idea to revise the original query and save hammering your database server.
For putting the data into an array of structs, Jake's answer works well.
如果要加入多个数据库,请确保在充当主键/外键的列上创建非聚集索引。
If you are joining multiple DB's make sure that you create a non-clustered index on the column(s) that will act as the primary/foreign keys.