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

做个留言版遇到2个有关问题。请高手帮帮忙啊苦恼

2012-12-17 
做个留言版遇到2个问题。。。请高手帮帮忙啊。苦恼本帖最后由 zkjd52 于 2012-10-25 02:32:01 编辑第一个问题:

做个留言版遇到2个问题。。。请高手帮帮忙啊。苦恼
本帖最后由 zkjd52 于 2012-10-25 02:32:01 编辑 第一个问题:留言板有个查询标题的模块,当查询不到东西就出错。网页打不开。当能查到东西的就能正常显示
第二个问题:当我输入内容查询后。比如页面比较多。我在文本框输入要跳转到第几页后,参数就消失了(第二个表单无法获取第一个表单keyword参数),等于显示全部记录了。。附全部代码:


<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="Connections/conngongsi.asp" -->
<%response.Charset="utf-8"%>
<%  keyword=request.QueryString("keyword")                       '获取keyword参数和建立记录集
    If (CStr(Request("MM_insert")) = "form1") Then
     if keyword=""then
 response.write " <script language='javascript'>"
         response.write "alert( '请输入内容后在查询! ');" 
         response.write "history.go(-1);"
         response.write "</script> "
 response.end
     end if
end if  
   sql="select * from book where book_biaoti like '%"&keyword&"%' ORDER BY ID DESC"
   set rs1=server.CreateObject("adodb.recordset")
   rs1.open sql,MM_conngongsi_STRING,1,3
  
%>
<%                                                         
rs1.pagesize=5                                           '分页代码
if request.QueryString("page")<>"" then
     epage=cint(request.QueryString("page"))
 if epage<1 then epage=1
     if epage>rs1.pagecount then epage=rs1.pagecount
     else
     epage=1
 end if
rs1.absolutepage=epage
%>
<% If (CStr(Request("yeshu")) = "form2") Then
       if request.QueryString("dpage")="" then                   '从表单dpage项获取要访问的页面
         response.write " <script language='javascript'>"
         response.write "alert( '请输入要到达的页数! ');" 
         response.write "history.go(-1);"
         response.write "</script> "
 response.end
   else 
       dwg=request.QueryString("dpage")
   response.redirect "lyb.asp?keyword="&keyword&"&page="&dwg&""
       end if
  end if
%>
<!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=utf-8" />
<title>留言簿</title>
<style type="text/css">
@import url("book_biaoti.css");

body,td,th {
font-size: 12px;
}
body {
margin-top: 0px;
background:url(tupian/bg.gif)
}
.size12 {
font-size: 12px;
}
</style>
<link href="book_biaoti.css" rel="stylesheet" type="text/css" />
</head>

<body >
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="192" colspan="7"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="801" height="270">
      <param name="movie" value="tupian/index.swf" />
      <param name="quality" value="high" />
      <param name="wmode" value="opaque" />
      <embed src="tupian/index.swf" quality="high" wmode="opaque" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="801" height="270"></embed>
    </object></td>
  </tr>
  <tr align="center">
    <td height="43" colspan="7" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#00ccFF">
      <tr>
        <td width="12%" height="43" align="center"><a href="index.asp" target="_top"><strong>首页</strong></a></td>
        <td width="12%" align="center"><strong>关于尚维</strong></td>
        <td width="12%" align="center"><strong>服务项目</strong></td>
        <td width="12%" align="center"><strong>收费标准</strong></td>
        <td width="12%" align="center"><strong>网站建设</strong></td>
        <td width="12%" align="center"><a href="fjsc.asp" target="_top"><strong>分享你的资源</strong></a></td>
        <td width="12%" align="center"><a href="lyb.asp" target="_top"><strong>留言簿</strong></a></td>
        <td width="12%" align="center"><a href="lianxi.asp" target="_top"><strong>联系我们</strong></a></td>
      </tr>
    </table></td>
  </tr>
  <tr><td colspan="5">
  
  </td>
    
  </tr>
  <tr>
   
    <td width="137" height="23"><strong>你的位置</strong>-- <a href="fbly.asp" target="_top">留言</a> 簿   </td>
    <form id="form1" name="form1" method="get" action=""><td width="51"  align="right">主题查询:</td>      


    <td width="205">
      <label for="keyword"></label>
      <input name="keyword" type="text" id="keyword" maxlength="20" style="width:200px;"/></td>
    <td width="161"><input type="submit" name="submit" id="submit" value="查询" />
      <input name="MM_insert" type="hidden" id="MM_insert" value="form1" /></td> 
    </form>
    <td width="248" >现在的时间是<%=now()%><a href="admin_login.asp" target="_top">管理员登陆</a></td>
  </tr>
  <tr>
    <td colspan="6" valign="top"> 
<% 
  for i=0 to rs1.pagesize-1
  if rs1.eof or rs1.bof then exit for                      '显示记录集的内容
%>
<table width="800" border="0" cellspacing="0" cellpadding="0">         
  <tr>
    <td width="96" height="26" bgcolor="#66FFFF">留言标题:</td>
    <td width="607" bgcolor="#66FFFF"><%response.write rs1("book_biaoti")%>&nbsp;</td>
    <td width="97" bgcolor="#66FFFF">ID:
      <%response.write rs1("ID")%>&nbsp;</td>
    </tr>
  <tr>
    <td height="26">留言内容:</td>
    <td colspan="2"><%response.write rs1("book_neirong")%>&nbsp;</td>
    </tr>
  <tr>
    <td height="27">留言时间:</td>
    <td colspan="2"><%response.write rs1("book_shijian")%>&nbsp;</td>
    </tr>
  <tr>
    <td height="23">留言者IP:</td>
    <td colspan="2"><%response.write rs1("book_ip")%>&nbsp;</td>
    </tr>
  <tr>
    <td height="26" >管理员回复:</td>
    <td height="26" colspan="2" ><%response.write rs1("book_huifuneirong")%></td>
  </tr>
</table>
<%
rs1.movenext()
next
%>
<% If rs1.eof and rs1.bof Then %>
  <p align="center"> 目前没有任何留言</p>
<% End If %>
<table width="501" border="0" align="left">
  <tr><td width="142" height="30"><strong>共有<%=rs1.recordcount%>个留言,第<%=epage%>/<%=rs1.pagecount%>页</strong></td><td width="130" align="left">
 <strong>
 <% if epage=1 then                                                                '分页代码
  response.write "首页"


  response.write "上一页"
  else  
  response.write "<a href='lyb.asp?keyword="&keyword&"&page=1'>首页</a>"
  response.write "<a href='lyb.asp?keyword="&keyword&"&page="&epage-1&"'>前一页</a>"
  end if 
 if epage=rs1.pagecount then
 response.write "下一页"
 response.write "末页"
 else
 response.write "<a href='lyb.asp?keyword="&keyword&"&page="&epage+1&"'>下一页</a>"
 response.write "<a href='lyb.asp?keyword="&keyword&"&page="&rs1.pagecount&"'>末页</a>"
 end if
%>
</strong></td>
<form id="form2" name="form2" method="get"><td width="35"><strong>跳转至</strong></td><td width="40"><input name="dpage" type="text" style="width:40px;" size="4" maxlength="4" onkeyup="value=value.replace(/[^\d]/g,'')" /></td><td width="13"><strong>页</strong></td><td width="115">  <input type="submit" value="确定"/>
  <input name="yeshu" type="hidden" id="yeshu" value="form2" /></td></form>
</tr>
 
</table>
</td>
  </tr>
  <tr>
    <td height="35" colspan="7" bgcolor="#00ccFF" align="center">Copyringht&nbsp;?&nbsp;2012-2112&nbsp;尚维公司版权所有.All Rights Reserved</td>
  </tr>
</table>
</body>
</html>
<%
rs1.Close()
Set rs1 = Nothing
%>


[解决办法]
提示什么错误?
[解决办法]
 rs1.open sql,MM_conngongsi_STRING,1,3
if not rs1.eof then
输出内容
end if
2 form2表单里 加keyword的隐藏域
[解决办法]


但是获取不了keyword参数。不知道如何做。点上页下页都能获取keyword参数

[解决办法]

引用:
theforever帮我解决这2个问题啊。。整页代码都帖出来了。帮我仔细瞧瞧啊
其中第2个问题这句是输入页数跳转response.redirect "lyb.asp?keyword="&amp;keyword&amp;"&amp;page="&amp;dwg&amp;"……

第一个问题:留言板有个查询标题的模块,当查询不到东西就出错。网页打不开。当能查到东西的就能正常显示

在keyword=request.QueryString("keyword") 之后应该检测传递来的keyword是否为空.
否则下面的SQL就有问题.
在查询结果之后,也应该检测一下记录集是否为空(即RS对象.EOF是否为真),如果是就结束输出页面.

第二个问题:当我输入内容查询后。比如页面比较多。我在文本框输入要跳转到第几页后,参数就消失了(第二个表单无法获取第一个表单keyword参数),等于显示全部记录了。。附全部代码:

<% If (CStr(Request("yeshu")) = "form2") Then
放置的位置也不对.
传参搞得没必要地多了一个环节.

全都是比较基础的地方犯错.所以我不具体回答,就是认为你应该回头从基础认真学学,不要漏掉中间重要的知识点.


[解决办法]
就算不检测有没有记录。没记录就不显示啊。有记录就显示啊。也不会出错啊
[解决办法]
好深奥啊
[解决办法]
引用:
好深奥啊

灌水啊。。
[解决办法]
我日。自己解决了。。这年头什么都得靠自己。。。鄙视。高手少啊。。

第一个问题解决方法
错在这句:rs1.absolutepage=epage
在前面加个记录集判断改为以下:
if NOT rs1.eof then
rs1.absolutepage=epage
end if

热点排行