asp读取数据库输出json
发布时间:2020-12-17 07:59:29 所属栏目:百科 来源:网络整理
导读:今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 Function GetTable(Table,Where,Order,OrderSort,curpage,pagesize,MiniJson)'Author : nigou'使用方法 : Response.Write GetTable(Table表名,Where条
以下代码由PHP站长网 52php.cn收集自互联网 现在PHP站长网小编把它分享给大家,仅供参考 Function GetTable(Table,Where,Order,OrderSort,curpage,pagesize,MiniJson) 'Author : nigou '使用方法 : Response.Write GetTable(Table表名,Where条件,Order主键(必须),OrderSort(asc,desc),curpage当前页,pagesize每页条数,MiniJson是否输出为miniUI格式) ' 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 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 以上内容由PHP站长网【52php.cn】收集整理供大家参考研究 如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |