展会信息港展会大全

ASP中SQL语句调用问题-首页如何调用推荐产品
来源:互联网   发布日期:2016-03-01 10:57:14   浏览:3199次  

导读: 如题!想要在网站首页调用推荐产品功能,而不是按产品ID排序调用,当前为由低到高调用,想改成调用推荐的产品,代码如下 <tr> <td height=...

如题!想要在网站首页调用推荐产品功能,而不是按产品ID排序调用,当前为由低到高调用,想改成调用推荐的产品,代码如下

<tr>

<td height="30" background="images/l2.gif"><div class="dd1">产品中心<span class="yf">PRODUCT CENTER</span><span class="more"><img src="images/mor.gif" width="7" height="7" /> <a href="products.asp" class="ma">更多…</a></span></div></td>

</tr>

<tr>

<td height="235" valign="top" background="images/l2.gif">

<%

set rp=server.CreateObject("adodb.recordset")

sql="select top 4 title,id,imgfrom products order by id desc "

rp.open sql,conn,1,1

if rp.eof and rp.bof then

response.Write("")

else

do while not rp.eof

%>

<div class="pro"> <a href="show.asp?id=<%=rp("id")%>"><img src="<%=rp("img")%>" alt="<%=rp("title")%>" width="108" height="83" border="0" /></a>

<a href="show.asp?id=<%=rp("id")%>"><%=rp("title")%></a></div>

<%

rp.movenext

loop

end if

rp.close

set rp=nothing

%>

</td>

</tr>

解决:

首先,看你的后台发布产品处是否有“推荐”设置。

如果没有则需要修改数据库,其中增加一个“推荐”字段,如istop(比如用数据类型,默认值0)

产品管理处设置推荐,只需修改istop的值即可,如rs("istop")=1(不为0表示为推荐产品)

然后在前台如此修改

sql="select top 4 title,id,istop,imgfrom products order by istop desc,id desc "

之所以用order by而不是where子句,是当推荐产品内容不足4条时也能正常显示

赞助本站

人工智能实验室

相关热词: 开发 编程 android

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港