问题描述
我的任务是首先重新排序网站上显示的具有最新产品(最高编号代码)的所有商品。当前,它们按输入顺序列出。该代码将以一个或两个字母开头,然后是一个数字值(即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 Update 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>