M
mzyang
Unregistered / Unconfirmed
GUEST, unregistred user!
在主页中采用下面的方法调用数据库内的文章
<script language="javascript" src="news.asp?typeid=1&n=5"></script>
想要达到显示typeid=1的栏目的头5条文章题目的目的,现运行后文章题目可以正常显示,
但题目条数的限制数n却没有作用,显示的是typeid=1栏目的所有文章题目。这是为何?
下面是news.asp:
<!--#include file="function/DBOpen.asp"-->
str="<style>A:link{text-decoration:none;color:black}A:visited{text-decoration:none;color:black}A:active{text-decoration:none}A:hover{text-decoration:underline;color:red}</style><table width=100% border=0 cellpadding=0 cellspacing=0>"
<%
function invert(str)
invert=replace(replace(replace(replace(str,"&lt;","<"),"&gt;",">"),"<br>",""),"&nbsp;"," ")
end function
kind=request("kind")
typeid=request("typeid")
borderid=request("borderid")
n=trim(request("n"))
n=int
if n="" or IsNumeric=false then
n=7
end if
set rs=server.createobject("adodb.recordset")
if kind="img" then
if typeid="" or IsNumeric(typeid)=false then
sql="select top 1 * from news where imgsize<>0 and audit=1 order by ntime DESC"
else
sql="select top 1 * from news where typeid=" &
cstr(typeid) &
" and imgsize<>0 and audit=1 order by ntime DESC"
end if
end if
if kind="hot" then
if typeid="" or IsNumeric(typeid)=false then
sql="select top " &
n &
" * from news where audit=1 order by hits DESC"
else
sql="select top " &
n &
" * from news where typeid=" &
cstr(typeid) &
" and audit=1 order by hits DESC"
end if
end if
if kind="" then
if typeid="" or IsNumeric(typeid)=false then
if borderid="" or IsNumeric(borderid)=false then
sql="select top " &
n &
" * from news where audit=1 order by ntime DESC"
else
sql="select top " &
n &
" * from news where borderid=" &
cstr(borderid) &
" and audit=1 order by ntime DESC"
end if
else
if borderid="" or IsNumeric(borderid)=false then
sql="select top " &
n &
" * from news where typeid=" &
cstr(typeid) &
" and audit=1 order by ntime DESC"
else
sql="select top " &
n &
" * from news where typeid=" &
cstr(typeid) &
" and borderid=" &
cstr(borderid) &
" and audit=1 order by ntime DESC"
end if
end if
end if
rs.open sql,conn,1,1
if not rs.eof and not rs.bof then
if kind="img" then
%>
str=str + "<tr><td valign=/"Middle/" align=/"center/" width=45%><a href='shownews.asp?newsid=<%=rs("newsid")%>' target=_blank><img src='showimg.asp?newsid=<%=rs("newsid")%>' border=0 width=110 height=81 alt='<%=trim(rs("topic"))%>'><br><%=rs("topic")%></a></td></tr>"
<%else
%>
str=str + "<tr><td width=100% align=left>"
<%do
while not rs.eof %>
str=str+"<li type=circle><a href=/"shownews.asp?newsid=<%=rs("newsid")%>/" target=_blank><%if cstr(rs("imgsize")) <>0 then
%><font color=/"#FF0400/" font size=/"1/">[图文]</font><%end if%><%=trim(rs("topic"))%></a><font color=/"#6365CE/" font size=/"1/">(<%theday=cstr(YEAR(rs("ntime")))&"-"&cstr(MONTH(rs("ntime")))&"-"&cstr(DAY(rs("ntime")))
response.write theday%>)</font><%if month(cdate(trim(rs("ntime"))))=month(now()) and clng(day(cdate(trim(rs("ntime"))))+1)>=clng(day(now())) then
%><img src=images/news.gif><%end if%>"
<% rs.movenext
loop %>
str=str + "</td></tr>"
<% end if
end if
rs.close
set rs=nothing
%>
str=str+ "</table>"
document.write (str)
<!--#include file="function/DBclose.asp"-->
<script language="javascript" src="news.asp?typeid=1&n=5"></script>
想要达到显示typeid=1的栏目的头5条文章题目的目的,现运行后文章题目可以正常显示,
但题目条数的限制数n却没有作用,显示的是typeid=1栏目的所有文章题目。这是为何?
下面是news.asp:
<!--#include file="function/DBOpen.asp"-->
str="<style>A:link{text-decoration:none;color:black}A:visited{text-decoration:none;color:black}A:active{text-decoration:none}A:hover{text-decoration:underline;color:red}</style><table width=100% border=0 cellpadding=0 cellspacing=0>"
<%
function invert(str)
invert=replace(replace(replace(replace(str,"&lt;","<"),"&gt;",">"),"<br>",""),"&nbsp;"," ")
end function
kind=request("kind")
typeid=request("typeid")
borderid=request("borderid")
n=trim(request("n"))
n=int
if n="" or IsNumeric=false then
n=7
end if
set rs=server.createobject("adodb.recordset")
if kind="img" then
if typeid="" or IsNumeric(typeid)=false then
sql="select top 1 * from news where imgsize<>0 and audit=1 order by ntime DESC"
else
sql="select top 1 * from news where typeid=" &
cstr(typeid) &
" and imgsize<>0 and audit=1 order by ntime DESC"
end if
end if
if kind="hot" then
if typeid="" or IsNumeric(typeid)=false then
sql="select top " &
n &
" * from news where audit=1 order by hits DESC"
else
sql="select top " &
n &
" * from news where typeid=" &
cstr(typeid) &
" and audit=1 order by hits DESC"
end if
end if
if kind="" then
if typeid="" or IsNumeric(typeid)=false then
if borderid="" or IsNumeric(borderid)=false then
sql="select top " &
n &
" * from news where audit=1 order by ntime DESC"
else
sql="select top " &
n &
" * from news where borderid=" &
cstr(borderid) &
" and audit=1 order by ntime DESC"
end if
else
if borderid="" or IsNumeric(borderid)=false then
sql="select top " &
n &
" * from news where typeid=" &
cstr(typeid) &
" and audit=1 order by ntime DESC"
else
sql="select top " &
n &
" * from news where typeid=" &
cstr(typeid) &
" and borderid=" &
cstr(borderid) &
" and audit=1 order by ntime DESC"
end if
end if
end if
rs.open sql,conn,1,1
if not rs.eof and not rs.bof then
if kind="img" then
%>
str=str + "<tr><td valign=/"Middle/" align=/"center/" width=45%><a href='shownews.asp?newsid=<%=rs("newsid")%>' target=_blank><img src='showimg.asp?newsid=<%=rs("newsid")%>' border=0 width=110 height=81 alt='<%=trim(rs("topic"))%>'><br><%=rs("topic")%></a></td></tr>"
<%else
%>
str=str + "<tr><td width=100% align=left>"
<%do
while not rs.eof %>
str=str+"<li type=circle><a href=/"shownews.asp?newsid=<%=rs("newsid")%>/" target=_blank><%if cstr(rs("imgsize")) <>0 then
%><font color=/"#FF0400/" font size=/"1/">[图文]</font><%end if%><%=trim(rs("topic"))%></a><font color=/"#6365CE/" font size=/"1/">(<%theday=cstr(YEAR(rs("ntime")))&"-"&cstr(MONTH(rs("ntime")))&"-"&cstr(DAY(rs("ntime")))
response.write theday%>)</font><%if month(cdate(trim(rs("ntime"))))=month(now()) and clng(day(cdate(trim(rs("ntime"))))+1)>=clng(day(now())) then
%><img src=images/news.gif><%end if%>"
<% rs.movenext
loop %>
str=str + "</td></tr>"
<% end if
end if
rs.close
set rs=nothing
%>
str=str+ "</table>"
document.write (str)
<!--#include file="function/DBclose.asp"-->