分頁

  • 46
  • 0

做個筆記, 類似Google分頁的風格

<%

    ''分頁
    Function MakePages(cp,tp) 'cp:目前第幾頁, tp:總頁數
      dim st, min, max , filename, fn

       filename = request.ServerVariables("SCRIPT_NAME")
       fn = getFileName(filename, true)

        min = 1
        if tp <= 10 then '總頁數<=10頁
           max = tp
        else                    ''總頁數>10頁
           if cp >=1 and cp <=6 then
                max = 10
           else
                if (cp+4) <= tp then
                    min = cp-5
                    max = cp+4
                else
                    max = tp
                    min = tp - 9
                end if
           end if
        end if
	 
      st = st & "<table border=0 width=40% >"
      st = st & "<tr>"

      if tp > 1 and CINT(cp) > 1 then
          st = st & "<td width=5% ><b><a href='" &fn& "?p="&(cp-1)&"'>" & "上一頁" & "</a></b></td>"
      else
        st = st & "<td  width=5% >" & "" & "</td>"
      end if
      for i = min to max
            if tp > 1 then
                if i = CINT(cp) then
                    st = st & "<td width=1% ><b><<a href='" &fn& "?p="&i&"'>" & i & "</a>></b></td>"
                else
                    st = st & "<td width=1% ><a href='" &fn& "?p="&i&"'>" & i & "</a></td>"
                end if 
            end if
       next
      if tp > 1 and CINT(cp) < tp then
          st = st & "<td width=5% ><b><a href='" &fn& "?p="&(cp+1)&"'>" & "下一頁" & "</a></b></td>"
	  else
        st = st & "<td  width=5% >" & "" & "</td>"
      end if
       st = st & "<td width=5% >共"&tp&"頁</td></tr>"
       st = st & "</table><hr>"
       MakePages = st
    end function 
	''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''回傳目前檔名
    Function getFileName(fpath, returnExtension)
        tmp = fpath
        if instrRev(tmp,"/") > 0 then
              tmp = mid(tmp, instrRev(tmp,"/")+1)
        end if
        if returnExtension = false then
              if instrRev(tmp,".") > 0 then
                    tmp = left(tmp, instrRev(tmp,".")-1)
              end if
        end if
        getFileName = tmp
	end Function
%>