过滤 cfquery 结果
我正在编辑已经存在的代码,这就是为什么这个问题是这样形成的。我正在尝试使用已存在的查询,并且不通过 url 添加更多表单变量。
所以我的问题是:我有一个正在运行的查询,并且该查询用于填充页面上的两个下拉列表。一个列表是运营状态,另一个是实际运营地点。在页面的开头,我希望下拉列表仅具有与查询不同的结果,当前它显示 120+ 'AL' 80+ 'MN' 等。此外,我希望第二个下拉列表仅具有具有以下内容的结果特定的状态作为他们的状态。
我知道我可以通过添加更多查询和表单变量来做到这一点,但我想知道是否有一种方法可以仅过滤 cfquery 中的结果。
I am editing already existing code, which is why this question is formed as it is. I am attempting to use a query that already exists and without adding more form variables through the url.
So my problem: I have a query that is being run, and this query is being used to populate two drop down lists on the page. One list is the state of operation, and the other is the actual site of operation. At the start of the page, I want the pull down to have only distinct results from the query, currently it is displaying 120+ 'AL' 80+ 'MN' etc. Additionally I want second pull down to only have results that have the particular state as their state.
I know I can do this by adding more querys, and with a form variable, but I am wondering if there is a way to just filter results in a cfquery.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这就是我要做的。仅首先显示状态下拉列表。
使用一些示例代码会更容易,但这里有一个示例。根本没有尝试过,但应该是一个不错的开始。永远不记得如何将选择设置回无选择...
第一个下拉菜单
第二个下拉菜单
添加一些 JavaScript...
Here's what I'd do. Only show the state drop down first.
This would be easier with some example code, but here's an example. Haven't tried it at all, but should be an okay start. Never remember how to set selects back to nothing selected...
First Drop Down
Second Drop Down(s)
Add some JavaScript...
第一个下拉列表的另一个答案+1 - 只需对输出进行分组(确保查询排序正确)。
对于第二个下拉列表 - 使用 cfselect 并查看绑定属性 - 您可以将其“绑定”到第一个下拉列表。
+1 on the other answer for the first drop down - just group the output (make sure query is ordered properly).
For the second drop down - use a cfselect and look at the bind attribute - you can "bind" it to the first dropdown.
这相当依赖于您的特定数据库设计...(此处为 MySQL 示例...)但是,完全假设您有一个字段将充当 PK 来定义站点位置,例如邮政编码(我正在使用它)在这里...)您可以简单地将 cfquery 转储到一个数组中,然后循环遍历它以获得结果...
This is rather dependent on your specific database design ... (MySQL example here ... ) However, completely presuming you have a field that will act as a PK to define the site locations, such as a ZipCode (which I'm using here ...) you could simply dump your cfquery into an array and then loop through that to get your results ...