js2.asp

来自「旅游管理系统 用ASP+SQL 2」· ASP 代码 · 共 87 行

ASP
87
字号
<!--#include file="conn.asp" -->
<%
'请保留以下信息
dim kind, path,classID,NclassID
kind=1              			'首页调用类型,1表示新文章,2表示热门文章
const dateNum=100         		'列出多少天内的热门文章
const maxLen=12			'主题最多显示字数,字母算一个汉字算两个
const listNum=9			'显示多少个文章标题
const bullet=""			'标题前的图片或符号
const hitColor="red"		'点击数的颜色
const new_color="red"		'新文章日期的颜色
const old_color="gray"		'旧文章日期的颜色
ClassID=request.querystring("classid")               '指定首页调用文章分类ID,全部分类不填
NclassID=request.querystring("nclassid")
dim rs,sql,str,str1,topicLen,topic
Path="http://"&request.servervariables("server_name")&replace(request.servervariables("script_name"),"js.asp","")


function gotTopic(str,strlen)
	dim l,t,c, i
	l=len(str)
	t=0
	for i=1 to l
	c=Abs(Asc(Mid(str,i,1)))
	if c>255 then
	t=t+2
	else
	t=t+1
	end if
	if t>=strlen then
	gotTopic=left(str,i)&"..."
	exit for
	else
	gotTopic=str
	end if
	next
end function

set rs=server.createObject("Adodb.recordset")
sql="select top "&listNum&" * from article"

if NclassID<>"" then
	sql=sql&" where NclassID="&NclassID
elseif classID<>"" then
	sql=sql&" where classID="&classID
end if

if kind=2 then
	if nclassid="" and classID="" then
		sql=sql&" where"
	else
		sql=sql&" and"
	end if
end if

select case kind
	case "1" sql=sql&" order by articleid desc"
	case "2" sql=sql&" DATEDIFF('d',dateandtime,Now())<="&dateNum&" order by hits desc,title"
end select

rs.open sql,conn,3,3
if rs.bof and rs.eof then 
str=str+"没有符合条件的文章"
else

rs.movefirst
do while not rs.eof
	topic=gotTopic(rs("title"),maxLen)
	topic=replace(server.HTMLencode(topic)," ","&nbsp;")
	topic=replace(topic,"'","&nbsp;")
	str=str+bullet &" <img src=images/dot3.gif>&nbsp;<font color=306ECB></font><a href='list.asp?id="+Cstr(rs("articleid"))+"' target='_blank'  title='"&replace(replace(server.HTMLencode(rs("title"))," ","&nbsp;"),"'","&nbsp;")&"') >"+Topic+"</a> <font color=306ECB>[</font>"
	
	str=str & "<font color=306ECB "
	if rs("dateandtime")>=date then
		str=str & new_color
 	else
		str=str & old_color
	end if
	str=str &"><font face=arial style=font-size: 8pt>" & Month(rs("DateAndTime"))&"</font>月<font face=arial style=font-size: 8pt>"&Day(rs("DateAndTime"))&"</font>日</font><font color=306ECB>]</font><br>"

	rs.moveNext
loop
end if
rs.close : conn.close
set rs=nothing : set conn=nothing
response.write "document.write ("&Chr(34)&str&Chr(34)&");"
%>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?