首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > vbScript >

请教小弟我要实现从另一个页面传值过来根据这个值从数据库取得数据显示当前页,可以在当前页点击上一条记录和下一条记录应该怎么实现

2012-02-16 
请问我要实现从另一个页面传值过来根据这个值从数据库取得数据显示当前页,可以在当前页点击上一条记录和下

请问我要实现从另一个页面传值过来根据这个值从数据库取得数据显示当前页,可以在当前页点击上一条记录和下一条记录应该如何实现.
<%@LANGUAGE="VBSCRIPT"%>

<!--#include file="../Connections/conn.asp" -->
<%
Dim detail__MMColParam
detail__MMColParam = "1"
If (Request.QueryString("productcode") <> "") Then 
  detail__MMColParam = Request.QueryString("productcode")
End If
%>
<%
Dim detail
Dim detail_numRows

Set detail = Server.CreateObject("ADODB.Recordset")
detail.ActiveConnection = MM_conn_STRING
detail.Source = "SELECT * FROM Product WHERE productcode = '" + Replace(detail__MMColParam, "'", "''") + "'"
detail.CursorType = 0
detail.CursorLocation = 2
detail.LockType = 1
detail.Open()

detail_numRows = 0
%>
<%
Dim plist
Dim plist_numRows

Set plist = Server.CreateObject("ADODB.Recordset")
plist.ActiveConnection = MM_conn_STRING
plist.Source = "SELECT * FROM line"
plist.CursorType = 0
plist.CursorLocation = 2
plist.LockType = 1
plist.Open()

plist_numRows = 0
%>
<%
Dim Repeat2__numRows
Dim Repeat2__index

Repeat2__numRows = -1
Repeat2__index = 0
plist_numRows = plist_numRows + Repeat2__numRows
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = -1
Repeat1__index = 0
plist_numRows = plist_numRows + Repeat1__numRows
%>


<%
Dim MM_paramName 
%>
<%
' *** Go To Record and Move To Record: create strings for maintaining URL and Form parameters

Dim MM_keepNone
Dim MM_keepURL
Dim MM_keepForm
Dim MM_keepBoth

Dim MM_removeList
Dim MM_item
Dim MM_nextItem

' create the list of parameters which should not be maintained
MM_removeList = "&index="
If (MM_paramName <> "") Then
  MM_removeList = MM_removeList & "&" & MM_paramName & "="
End If

MM_keepURL=""
MM_keepForm=""
MM_keepBoth=""
MM_keepNone=""

' add the URL parameters to the MM_keepURL string
For Each MM_item In Request.QueryString
  MM_nextItem = "&" & MM_item & "="
  If (InStr(1,MM_removeList,MM_nextItem,1) = 0) Then
  MM_keepURL = MM_keepURL & MM_nextItem & Server.URLencode(Request.QueryString(MM_item))
  End If
Next

' add the Form variables to the MM_keepForm string
For Each MM_item In Request.Form
  MM_nextItem = "&" & MM_item & "="
  If (InStr(1,MM_removeList,MM_nextItem,1) = 0) Then
  MM_keepForm = MM_keepForm & MM_nextItem & Server.URLencode(Request.Form(MM_item))
  End If
Next

' create the Form + URL string and remove the intial '&' from each of the strings
MM_keepBoth = MM_keepURL & MM_keepForm
If (MM_keepBoth <> "") Then 
  MM_keepBoth = Right(MM_keepBoth, Len(MM_keepBoth) - 1)
End If
If (MM_keepURL <> "") Then
  MM_keepURL = Right(MM_keepURL, Len(MM_keepURL) - 1)
End If
If (MM_keepForm <> "") Then
  MM_keepForm = Right(MM_keepForm, Len(MM_keepForm) - 1)
End If

' a utility function used for adding additional parameters to these strings
Function MM_joinChar(firstItem)
  If (firstItem <> "") Then
  MM_joinChar = "&"
  Else
  MM_joinChar = ""
  End If
End Function
%>
<script language="javascript" src="Tips.js"></script>


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
<style type="text/css">
<!--
-->
</style>
<link href="../style.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.datap13 {
font-size: 13px;
background-position: left top;
}
-->
</style>
</head>
<body text="333333" link="ff9900" vlink="666600" alink="990000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<div align="center"></div>
<div align="center"> 
  <table width="980" border="0" cellpadding="0" cellspacing="0">
  <!--DWLayoutTable-->
  <tr> 
  <td width="980" height="472" valign="top"> <table width="100%" border="0" cellpadding="0" cellspacing="0">
  <!--DWLayoutTable-->
  <tr> 
<td width="669" valign="top" > <table width="100%" border="0" cellpadding="0" cellspacing="0" class="p20">
  <!--DWLayoutTable-->
  <tr> 
  <td width="649" height="5"></td>
  <td width="9"></td>
  </tr>
  <tr> 
  <td height="33" colspan="2" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFCCCC">
  <!--DWLayoutTable-->
  <tr> 
   
<td colspan="2" valign="middle" height="40" align="left" background="../images/productb.jpg" style="font-size:14px; font-weight:600">
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  產品名稱:<%=(detail.Fields.Item("productname").Value)%>
</td>

  </tr>
   
  </table></td>
  </tr>
   
  <tr> 
  <td height="377" valign="top"> <table width="100%" border="0" cellpadding="0" cellspacing="0">
  <!--DWLayoutTable-->
  <tr> 
  <td width="32" >&nbsp;</td>
  <td width="180">&nbsp;</td>
  <td width="197" rowspan="4" align="center" valign="middle" height="140" background="../images/ny/kuang1.jpg"><img src="../Shopping/product_images/<%=(detail.Fields.Item("productcode").Value)%>.jpg" width="120" height="120" ></td>
  <td width="5">&nbsp;</td>
  <td width="170">&nbsp;</td>
  <td width="42">&nbsp;</td>


  </tr>
  <tr> 
  <td height="247"></td>
  <td colspan="4" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
  <!--DWLayoutTable-->
  <tr> 
  <td width="575" height="231" valign="top" class="datap13"><%=(detail.Fields.Item("description").Value)%></td>
  </tr>
  </table></td>
  <td>&nbsp;</td>
  </tr>
  </table></td>
  <td>&nbsp;</td>
  </tr>
  </table></td>
  </tr>
  <tr> 
  <td height="19">&nbsp;</td>
  <td>&nbsp;</td>
  </tr>
  </table></td>
  </tr>
  </table>
</div>
</body>
</html>
<%
detail.Close()
Set detail = Nothing
%>
<%
plist.Close()
Set plist = Nothing
%>


[解决办法]
rs.movenext
rs.movefirst
[解决办法]
既然在当前页你已经显示出当前记录了,那么必然知道这条记录的主键和排序字段
剩下的就很简单了
根据排序字段排序,取出主键之前和之后的一条记录即可
例如主键为id,排序为日期倒序
id=rs("id")这是页面上当前记录的ID

sql="select top 1 [id],[title] from [tablename] where [id]>"&id&" order by [pubdate]"
这是前一篇


sql="select top 1 [id],[title] from [tablename] where [id]<"&id&" order by [pubdate] desc"
这是后一篇

热点排行