- 爱易网页
-
ASP教程
- 怎么优化这代码,希望大家帮帮小女孩,因为刚刚入这行
日期:2014-05-17 浏览次数:21067 次
如何优化这代码,希望大家帮帮小女孩,因为刚刚入这行!
数据库news有四个字段顺序主id,sname,sdate,stype
<table >
<%
sql= "SELECT id,sname,sdate FROM news where stype= '新闻类别1 ' order by id desc "
set rs=server.createobject( "adodb.recordset ")
rs.open sql,conn,1,1
if rs.eof then
response.Write( " <center> <br> <br> 暂时还没有相关内容! </center> ")
else
do while not rs.eof
%>
<tr> <td> <a href= "one.asp?id= <%=rs( "id ")%> " > <%=trim(rs( "sName "))%> </a> <%=trim(rs( "sdate "))%> </td> </tr>
<%
rs.movenext
loop
end if
rs.close
set rs=nothing
%>
</table>
<table >
<%
sql= "SELECT id,sname,sdate FROM news where stype= '新闻类别2 ' order by id desc "
set rs=server.createobject( "adodb.recordset ")
rs.open sql,conn,1,1
if rs.eof then
response.Write( " <center> <br> <br> 暂时还没有相关内容! </center> ")
else
do while not rs.eof
%>
<tr> <td> <a href= "one.asp?id= <%=rs( "id ")%> " > <%=trim(rs( "sName "))%> </a> <%=trim(rs( "sdate "))%> </td> </tr>
<%
rs.movenext
loop
end if
rs.close
set rs=nothing
%>
</table>
在网站站首页时,多处有这种程序代码出现,所以页面很慢,如何优化这代码!
问题是 "就是如何写,才让页面打开快一点 "
包括如何用dim 定义.希望大家帮帮小女孩,因为刚刚入这行!
------解决方案--------------------
<%
Dim sql,rs
Set rs = server.createobject( "adodb.recordset ")
%>
<table >
<%
sql= "SELECT id,sname,sdate FROM news where stype= '新闻类别1 ' order by id desc "
rs.open sql,conn,1,1
if rs.eof then
response.Write( " <center> <br> <br> 暂时还没有相关内容! </center> ")
else
do while not rs.eof
%>
<tr> <td> <a href= "one.asp?id= <%=rs( "id ")%> " > <%=trim(rs( "sName "))%> </a> <%=trim(rs( "sdate "))%> </td> </tr>
<%
rs.movenext
loop
end if
rs.close
%>
</table>
<table >
<%
sql= "SELECT id,sname,sdate FROM news where stype= '新闻类别2 ' order by id desc "
rs.open sql,conn,1,1
if rs.eof then
response.Write( " <center> <br> <br> 暂时还没有相关内容! </center> ")
else
do while not rs.eof
%>
<tr> <td> <a href= "one.asp?id= <%=rs( "id ")%> " > <%=trim(rs( "sName "))%> </a> <%=trim(rs( "sdate "))%> </td> </tr>
<%
rs.movenext
loop
end if
rs.close
%>
</table>
<%