The code is as follows:
Function gettable (Table,where,order,ordersort,curpage, Pagesize,minijson)
' Author:nigou
' Use method: Response.Write gettable (table name, where condition, order primary key (required), Ordersort (ASC,DESC), curpage current page, pagesize per page number, Minijson is output as MINIUI format)
'
Dim i, J, RS
If ordersort= "" Then ordersort= "ASC"
If where= "" Then where= "ASC"
Set rs=server.createobject ("Adodb.recordset")
If Curpage>1 Then
Tmpsql= Select A.* from (select Top & (curpage) * pagesize & "* from" & Table & "where" & where & ' ORDER BY ' & Order & ' & Ordersort & ' A LEFT join (select top & (curpage-1) * pagesize & "* from" & Table & "where" & Where & "ORDER BY" & Order & "" & Ordersort & " B on A. "& Order &" =b. "& Order &" where IIf (b. "& Order &", ' 0 ', ' 1 ') = ' 1 ' "
Else
Tmpsql= Select A.* from (select Top & (curpage) * pagesize & "* from" & Table & "where" & where & "ORDER BY" & Order & "& Ordersort &") a "
End If
If pagesize=0 Then tmpsql = "SELECT * from" & Table
Rs.Open tmpsql,conn,1,1
Realsize=rs.recordcount
For I=0 to Rs.recordcount-1
tmpjson= Tmpjson & "{"
For J=0 to Rs.fields.count-1
tmpjson= Tmpjson & "" "& (Rs.fields (j). Name) &" ":"
tmpjson= Tmpjson & "" "& Rs (J) &" ""
If J<rs.fields.count-1 then tmpjson= Tmpjson & ","
Next
tmpjson= Tmpjson & "}"
If I<rs.recordcount-1 then tmpjson= Tmpjson & ","
tmpjson= Tmpjson & vbCrLf
Rs.movenext
Next
Rs.close
If Minijson=1 Then
Countsql= "SELECT COUNT (" & Order & ") from" & Table & "where" & where
Rs.Open countsql,conn,1,1
Counts=rs (0)
Rs.close
GETTABLE=TOMINIUI (tmpjson,counts)
Else
Gettable=tojson (Tmpjson)
End If
Set rs=nothing
End Function
function Tojson (JSONSTR)
Tojson= "[" & vbCrLf & Jsonstr & vbCrLf & "]"
End Function
Function Tominiui (jsonstr,total)
Tominiui= "{"
TOMINIUI=TOMINIUI & "" "Total" ":" "& Total &" "," & vbCrLf
TOMINIUI=TOMINIUI & "" "Data" ": [" & Jsonstr
TOMINIUI=TOMINIUI & "]}"
End Function
PS: The last parameter is developed for MINIUI, can ignore
The above is the entire content of this article, I hope you can enjoy.