读书人

兄弟们会的都进来帮帮忙好吗?关于首

发布时间: 2012-02-23 22:01:35 作者: rapoo

兄弟们,会的都进来帮帮忙好吗?关于首页调用最新数据的问题
<%
dim zs:zs = 9 '===== 提取的文章数量
dim cols:cols = 3 '==== 列数

sn = 0
sql= "select top 9 id,s_name from info_shop where ifhome=1 and ifvalid=1 order by id asc "
rs.open sql,conn,1,1
if not rs.eof then
do while not rs.eof
sn = sn + 1

sid=rs( "id ")
set rs2=server.createobject( "adodb.recordset ")
sqltt= "select top 1 sid ,id from dazhe_info where sid= ' "&sid& " ' order by id desc "
rs2.open sqltt,conn,1,1
If not rs2.eof Then

set rs1=server.createobject( "adodb.recordset ")
sqlt= "select top 5 sid ,spic from pic_shop where sid= ' "&sid& " ' order by id desc "
rs1.open sqlt,conn,1,1
%>
<td width= "33% "> <table width= "96 " border= "0 " cellpadding= "0 " cellspacing= "0 ">
<tr>
<td> <div align= "center ">
<table width= "87 " border= "0 " cellpadding= "0 " cellspacing= "0 ">
<tr bgcolor= "#CFCFCF ">
<td colspan= "3 " height= "1 "> </td>
</tr>
<tr>


<td width= "1 " bgcolor= "#CFCFCF " height= "11 "> </td>
<td height= "55 "> <div align= "center "> <a href= "show.asp?id= <%=rs2( "id ")%> " target= "_blank " >
<%if not rs1.eof then
%>
<img src= 'imgweb/ <%=rs1( "spic ")%> ' width= "102 " height= "68 " border= "0 " />
<%else%>
<img src= 'imgweb/noimg.gif ' width= "102 " height= "68 " border= "0 " />
<%end if%>
</a> </div> </td>
<td width= "5 " bgcolor= "#CFCFCF " height= "11 "> </td>


</tr>
<tr bgcolor= "#CFCFCF ">
<td colspan= "3 "
height= "1 "> </td>
</tr>
</table>
</div> </td>
</tr>
<tr>
<td height= "20 " width= "102 "> <div align= "center "> <a href= "show.asp?id= <%=rs2( "id ")%> " target= "_blank ">
<% if len(rs( "s_name "))> 8 then%>
</a> <a href= "show.asp?id= <%=rs2( "id ")%> " target= "_blank "> <%=left(rs( "s_name "),8)%> </a> <a href= "show.asp?id= <%=rs2( "id ")%> " target= "_blank ">


<% else%>
<%=rs( "s_name ")%>
<%end if%>
</a> </div> </td>
</tr>
</table> </td>
<%
rs1.close
End If '--1
rs2.close

If sn = cols Then
sn = 0
Response.Write( " </tr> <tr align=center valign=top> ")
End If
rs.movenext
Loop
end if


rs.close
%>


这个是首页INDEX.ASP的源代码,现在问题就是:我在后台提交了新的数据后,首页无法显示新添加的数据,还是原来的,就是说数据是从旧到新排列,而不是像平时的从新到旧,会的兄弟都帮帮忙好吗?

[解决办法]
不是数据新旧的问题,表info_shop 里面id 是主键吧,新加的数据 ID 应该比原来的大,是逐渐增加的,但是你的sql是:
select top 9 id,s_name from info_shop where ifhome=1 and ifvalid=1 order by id asc

是按照ID 升序排列后 选出来前9行,也就是选出来ID最小的9行,当原来你的数据在9行以上时,你加的数据就显示不出来了

如果要显示最近加入新数据,还要显示9 行
可以用
select top 9 id,s_name from info_shop where ifhome=1 and ifvalid=1 order by id DESC

如果不限制显示多少行 把 top 9 去掉就可以了


[解决办法]
sn = 0
sql= "select top 9 id,s_name from info_shop where ifhome=1 and ifvalid=1 order by id asc "
rs.open sql,conn,1,1
if not rs.eof then
do while not rs.eof
sn = sn + 1
========================================改为:
sn = 0
sql= "select top 9 id,s_name from info_shop where ifhome=1 and ifvalid=1 order by id desc "
rs.open sql,conn,1,1
if not rs.eof then
do while not rs.eof
sn = sn + 1
试下
[解决办法]
order by 的用途看来楼主是没有搞清楚


order by id 或order by id asc 表示的是按ID小-》大的顺序显示
order by id desc 和上面的相反。

当 order by id asc时,可以写成order by id,系统默认为asc。

读书人网 >SQL Server

热点推荐