注册 登录
编程论坛 ASP技术论坛

评论怎样按最新发表排列??有代码懂的来看看,谢谢!

po09999 发布于 2013-04-05 07:51, 1250 次点击
意思是说:在内容页显示把最新发表的排在最上面,以前发表的排后面。
应该是这个文件:\plug\comment\commentList.asp

程序代码:
<%
commentList
Sub commentList
    Response.Buffer
=True
    Response.ContentType
="text/html;charset=gbk"
   
Dim rsObj,ContentID,page,pCount,pSize,i,pagerStr,pPage,nPage,numPage
    pSize
=5        '评论显示数
    numPage=5    '显示页码数
    ContentID=filterPara(getForm("id","get"))
    page
=filterPara(getForm("page","get"))
   
   
dim sql
   
if SwitchCommentsStatus=0 then
        sql
="select * from {prefix}Comments where ContentID="&ContentID
   
else
        sql
="select * from {prefix}Comments where CommentStatus=1 and ContentID="&ContentID   
   
end if
   
set rsObj=conn.Exec(sql,"r1")   
   
   
if not rsObj.eof then
        rsObj.pageSize
=pSize
        pCount
=rsObj.pageCount
        
if isNul(page) or not isnum(page) or page<1 then page=1 else page=clng(page)
        
if page>pCount then page=pCount
        rsObj.absolutepage
= page
        
for i = 1 to pSize         
            echo
"<div class=""clistbox"">" &vbcrlf& _
            
"<div class=""line1""><span>发表于:"&rsObj("AddTime")&"</span> 评论者:"&filterDirty(rsObj("Commentator"))&" </div>" &vbcrlf& _
            
"<div class=""line2"">"&filterDirty(rsObj("CommentContent"))&"</div>" &vbcrlf& _
            
"</div>" &vbcrlf         
            rsObj.moveNext
            
if rsObj.eof then exit for
        
next
        
        pagerStr
=makePageNumber(page, numPage, pCount, "commentlist",ContentID,"")        
        
if page>1 then pPage=page-1 else pPage=1
        
if page=pCount then nPage=page else nPage=page+1
        
        echo
"<div class=""pages"">"&"<a href=""javascript:pager("&ContentID&",1)"">首页</a><a href=""javascript:pager("&ContentID&","&pPage&")"">上一页</a>"
        echo pagerStr
        echo
"<a href=""javascript:pager("&ContentID&","&nPage&")"">下一页</a>"&"<a href=""javascript:pager("&ContentID&","&pCount&")"">末页</a>"&"</div>"
   
else
        echo
"还没有评论!"
   
end if
    rsObj.close()
   
set rsObj=nothing
End Sub
%>


怎么改呢?
7 回复
#2
elongtown2013-04-05 10:00
sql改成:sql="select * from {prefix}Comments where ContentID="&ContentID&"order by ContentID DESC"

sql="select * from {prefix}Comments where CommentStatus=1 and ContentID="&ContentID&"order by ContentID DESC"

你试试
#3
hu9jj2013-04-05 10:17
也可以按发表日期排序。
#4
po099992013-04-05 12:07
回复 2楼 elongtown
提示错误!
提示:【执行SQL语句错误】
错误号:-2147217900
错误描述:语法错误 (操作符丢失) 在查询表达式 'ContentID=75order by ContentID DESC' 中。sql=select * from AspCms_Comments where ContentID=75order by ContentID DESC
#5
hu9jj2013-04-05 21:14
你的表中记录日期时间或者自动编号的字段是哪个,以这个字段降序排序就成。
#6
po099992013-04-06 06:51
回复 5楼 hu9jj
好像是这个:评论时间:"&now()
那代码应该怎么改呢?谢谢!
#7
hu9jj2013-04-06 07:32
以下是引用po09999在2013-4-6 06:51:42的发言:

好像是这个:评论时间:"&now()
那代码应该怎么改呢?谢谢!
这是取得当前时间的函数,不是字段名。
#8
po099992013-04-07 09:04
回复 7楼 hu9jj
你好,又要麻烦你一下了~谢谢!
我今天把打开数据库了,请你看一下下面的附件图片。
只有本站会员才能查看附件,请 登录

那这两句代码该怎样改呢?
猀焀氀="select * from {prefix}Comments where ContentID="&ContentID
 else
猀焀氀="select * from {prefix}Comments where CommentStatus=1 and ContentID="&ContentID
 end if
1