用于前台操作数据表排序字段的研究

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
'用于前台操作数据表排序字段的研究
'作者:周培公
'数据库:d.mdb
'数据表:t
'字段:ID,name,orderID 
 dim conn
 Set conn = Server.CreateObject("ADODB.Connection")
 conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("d.mdb")

  If Request.form("a")<>"" Then
  dim arrTest
  arrTest=Request.form("a")
  response.Write(arrTest)
  dim arrT
  arrT=split(arrTest,"|")
  dim j,arT1,arT2
  arT1=split(arrT(0),",")'第一个数是ID,第二个数是orderID
  arT2=split(arrT(1),",")
  conn.exeCute("update t set orderID="&arT1(1)&" where id="&arT1(0))
  conn.exeCute("update t set orderID="&arT2(1)&" where id="&arT2(0))
  response.Redirect("index.asp")
 else

 dim sql,rs
 sql="select * from t order by orderID"
 Set rs= Server.CreateObject("ADODB.Recordset")
 rs.open sql,conn,1,3
 if not rs.bof and not rs.eof then
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>前台排序研究</title>
</head>
<body>
 <% 
  dim intCounter
  intCounter=0
  dim lastCountIndex
  lastCountIndex=rs.recordcount-1
  do while not rs.eof
   %>
   <%= rs("id") %>、<%= rs("name") %>---<%= rs("orderID") %>
   &nbsp;&nbsp;
   [
   <%
   If intCounter<>0 Then
   %>
  <a href="#"  οnclick="upOder(<%= intCounter %>);return false;">升</a>
  <%
   End If
   If intCounter<>lastCountIndex Then
   %>
  <a href="#" οnclick="downOder(<%= intCounter %>);return false;">降</a>
  <%
   End If
   %>
  ]<br />
<%
  intCounter=intCounter+1
  rs.movenext
  loop
 %>
<form id="f" name="f" method="post" action="">
<input name="a" type="hidden" value="" />
</form>
<script language="javascript">
<!--
 var t_ID;
 var t_orderID;
 t_ID=new Array();
 t_orderID=new Array();
 <% 
  dim t,i
  rs.movefirst
  dim f(1)
  f(0)="ID"
  f(1)="orderID"
  'getrows方法,
  '第一个参数是所取得记录的数量(默认-1指全部),第二个参数是开始处的标签,第二个是字段
  '结果数组的第一维是取得的字段数量,第二维是取得的记录数量
  t=rs.getrows(-1,1,f)
  for i=0 to UBOUND(t,2)
  %>
   t_ID[<%= i %>]=<%= t(0,i) %>;
   t_orderID[<%= i %>]=<%= t(1,i) %>;
  <% 
  next
 %>
 function upOder(i)
 {
  document.all.a.value=t_ID[i];
  document.all.a.value+=","+t_orderID[i-1];
  document.all.a.value+="|"+t_ID[i-1];
  document.all.a.value+=","+t_orderID[i];
  document.all.f.submit();
 }
 function downOder(i)
 {
  document.all.a.value=t_ID[i];
  document.all.a.value+=","+t_orderID[i+1];
  document.all.a.value+="|"+t_ID[i+1];
  document.all.a.value+=","+t_orderID[i];
  document.all.f.submit();
 }
//-->
</script>
</body>
</html>
<% 
  end if
 End If
 rs.close
 set rs=nothing
 conn.close
 set conn=nothing
%> 

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值