Loops 需要帮助在旧ColdFusion站点中按相反顺序列出产品吗
我的任务是首先用最新产品(最高编号)重新订购网站上显示的所有商品。目前,它们是按条目顺序列出的。代码将以一个或两个字母开头,然后是一个数值(ie 001-1200) 这是当前带有代码的基本页面,显示范围和类别,我相信该网站/代码大约有15年历史 提前谢谢Loops 需要帮助在旧ColdFusion站点中按相反顺序列出产品吗,loops,coldfusion,cfml,cfoutput,Loops,Coldfusion,Cfml,Cfoutput,我的任务是首先用最新产品(最高编号)重新订购网站上显示的所有商品。目前,它们是按条目顺序列出的。代码将以一个或两个字母开头,然后是一个数值(ie 001-1200) 这是当前带有代码的基本页面,显示范围和类别,我相信该网站/代码大约有15年历史 提前谢谢 <div id="content"> <cfinclude template="../core_includes/top_menu.cfm"> <div id
<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>
#range.range\u名称#
#category.category\u名称#
目前没有此类产品。请提供更多信息。
解决方案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>
请参阅:只需将
产品
查询中的排序顺序更改为所需的顺序即可。代码中不需要任何更改。@Miguel-F回答这个问题。添加一个简单的ORDER BY语句的示例。也许否决该语句的人可以解释原因。