Skip navigation.

永远的亚特兰缔斯

To record my thinking and study note

Posts tagged with "vbscript"

关于无限分级的一种算法思路

, , , ...

一种无限分级的算法思路,可用于任何应用无限分类的地方,比如菜单、新闻、产品等。
(其实是用到了递归算法)
调用:PrintClass 0,1
设置:添加的时候把顶级的Class的ParentId设定为0,ChildId设定为1
备注:ClassName-类别名称,ParentId-父级Id,ChildId-所处等级,顶级为1,二级为2...

数据表结构
Create Table tClass(
Id int identity(1,1) not null ,
ClassName varchar(50) ,
ParentId int ,
ChildId int ,
primary key(Id)
)


实现函数
'*************************************
'Coded By hooline 2006.5.19
'Email:hooline#gmail.com
'Msn:peace.zhou#msn.com
'**************************************
function PrintClass(ParentId,ChildId)
  dim objRs,strSql,i
  dim strSpace
  set objRs=server.CreateObject("adodb.recordset")
  strSql="Select * from tClass where ParentId="&ParentId&""
  objRs.Open strSql,objConn,3,1
  if not objRs.EOF then       
       strSpace=""
       while not objRs.EOF
          for i=1 to ChildId-1
             strSpace=strSpace+"--"
          next
          response.Write strSpace&objRs("ClassName")&"<br />"
          PrintClass objRs("Id"),ChildId+1
          objRs.MoveNext
          strSpace=""
        wend
  end if
  objRs.Close
  set objRs=nothing
end function

关于较长文章手动分页的实现方法

, ,

这里介绍一种对较长文章手动分页的实现,代码用Asp的Vbscript实现。

程序思路:
1.在后台加入文章时,手动加入分页符$page
2.前台显示时,根据资料中的分页符,用Vbscript中的Split函数取出到数组中
3.从数组中取出相应的资料内容

'*************************************
'Coded By hooline 2006.5.18
'Email:hooline#gmail.com
'Msn:peace.zhou#msn.com
'**************************************
Dim szArray,page
Dim objRs,strSql,sContent
dim j
page = request.querystring("page")
strSql = "select * from Articles where Aid="&Request("Aid")
Set objRs = server.CreateObject("adodb.recordset")
objRs.open strSql,objConn,3,1
If Not objRs.eof Then
   sContent = objRs("ArticleContent")
   szArray = Split(sContent,"$page")
   If UBound(szArray)>=1 Then
    If page="" Or IsNull(page) Or (Not IsNumeric(page)) Then
       page=1
    End if
    response.write szArray(page-1)
    response.write "<br />"
    response.write "分页: "
For j=0 To UBound(szArray)
  response.write "<a href='ShowArticle.asp?AId="&Request("AId")&"&page="&j+1&"'>"&j+1&"</a>&nbsp;"
next
   else
    response.write szArray(0)
   End if
  Else
   response.write "no record"
End If

objRs.close
Set objRs=Nothing
January 2010
S M T W T F S
December 2009February 2010
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30