loops - 需要帮助在旧的 ColdFusion 站点中以相反的顺序列出产品
问题描述
我的任务是首先使用最新产品(最高数字代码)重新订购网站上显示的所有项目。目前,它们按进入顺序列出。代码将以单字母或双字母开头,然后是数值(即 001-1200)
这是当前带有显示范围和类别的代码的基本页面,我相信该网站/代码大约有 15 年历史......
提前致谢
<div id="content">
<cfinclude template="../core_includes/top_menu.cfm">
<div id="template_box2">
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td valign="top">
<cfinclude template="../core_includes/left_menu.cfm">
</td>
<td valign="top">
<div id="template_right">
<div id="template_right_topbar"></div>
<div id="template_right_content" <cfif products.recordcount eq 0>style="height:480px;"</cfif> <cfif products.recordcount lte 24>style="height:480px;"</cfif>>
<div style="padding-bottom:10px;">
<span class="template_header1"><cfoutput>#range.range_name#</cfoutput></span>
</div>
<div style="padding-bottom:12px;">
<span class="template_header5"><cfoutput>#category.category_name#</cfoutput></span>
</div>
<div <cfif products.recordcount eq 0>style="padding-top:14px;"</cfif>>
<cfif products.recordcount gt 0>
<cfoutput query="products">
<a href="index.cfm?content=product&range_id=#range.range_id#&category_id=#category.category_id#&product_id=#products.product_id#" target="_self" alt="#products.code#"><img src="#products.image_1_thumb#" width="88" height="88" border="0" alt="#products.code#" title="#products.code#" style="margin-right:4px;margin-bottom:3px;border: 2px solid ##484848;"></a>
</cfoutput>
<cfelse>
<span class="template_header2">There are currently no products in this category. Please <a href="mailto:*.*">email us</a> for more information.</span>
</cfif>
</div>
</div>
<div id="template_right_bottombar"></div>
</div>
</td>
</tr>
</table>
</div>
<cfinclude template="../core_includes/footer.cfm">
</div>
解决方案
解决方案 1
更改查询中的排序顺序,使其顺序正确。这是比解决方案 2 更好的解决方案
解决方案 2
向后循环查询。
我已将链接分成几部分以使其更清晰。需要删除换行符。
<cfoutput>
<cfloop from="#products.recordcount#" to="1" step="-1" index="i">
<a href="index.cfm?content=product
&range_id=#range.range_id#
&category_id=#category.category_id#
&product_id=#products.product_id[i]#" target="_self" alt="#products.code[i]#">
<img src="#products.image_1_thumb[i]#" width="88" height="88" border="0"
alt="#products.code[i]#"
title="#products.code[i]#" style="margin-right:4px;margin-bottom:3px;border: 2px solid ##484848;">
</a>
</cfloop>
</cfoutput>
解决方案 2 改进
数据还需要正确编码
<cfoutput>
<cfloop from="#products.recordcount#" to="1" step="-1" index="i">
<a href="index.cfm?content=product
&range_id=#EncodeForURL(range.range_id)#
&category_id=#EncodeForURL(category.category_id)#
&product_id=#EncodeForURL(products.product_id[i])#" target="_self" alt="#EncodeForURL(products.code[i])#">
<img src="#EncodeForHTMLAttribute(products.image_1_thumb[i])#" width="88" height="88" border="0"
alt="#EncodeForHTMLAttribute(products.code[i])#"
title="#EncodeForHTMLAttribute(products.code[i])#" style="margin-right:4px;margin-bottom:3px;border: 2px solid ##484848;">
</a>
</cfloop>
</cfoutput>
解决方案 3
如果您有 CF 2018 更新 5 或更高版本
<cfset products = products.reverse()>
<cfoutput query="products">
<a href="index.cfm?content=product&range_id=#range.range_id#&category_id=#category.category_id#&product_id=#products.product_id#" target="_self" alt="#products.code#"><img src="#products.image_1_thumb#" width="88" height="88" border="0" alt="#products.code#" title="#products.code#" style="margin-right:4px;margin-bottom:3px;border: 2px solid ##484848;"></a>
</cfoutput>
推荐阅读
- php - 当我有超过 25 个总变体时,Woocomerce 不允许我向篮子添加变体
- c# - 验证强制延迟初始化服务
- java - 在服务器端拦截 RMI 调用
- mysql - LOAD DATA INFILE 和空间数据
- excel - 使用 VBScript 删除 Excel 工作表
- java - 在 IBM Notes 中发送 HTTPS 帖子时出现 SSLHandshakeException
- istio - Istio virtualService 是否总是需要 DestinationRule?
- actionscript-3 - AS3 hitTestObject 不工作
- c# - 带有 ClientTemplate Kendo Grid 的可空布尔值
- qlikview - 主脚本中无法识别的别名