Hallo allerseits,
ich weiss, das hier ist kein ASP Forum, aber vielleicht hat trotzdem jemand die Muse sich das hier mal anzuschauen.
Das Skript erstellt zuerst eine Suchmaske fuer meine Datenbank. Nach erfolgreicher Suche werden die Treffer angezeigt. Genau hier liegt mein Problem. Es sollen jeweils 10 Treffer pro Seite angezeigt werden. Bei den ersten zehn funktioniert das noch reibungslos, aber wenn ich zu den naechsten 10 springen moechte verschwinden meine Suchkriterien und ich hab wieder ein leeres Eingabefeld. Irgendwo gehen also meine Daten verloren. Hat jemand eine Idee?
<% @Language = VBScript %> <% Option Explicit Response.Expires = 0 Response.Buffer = True %>
<!--#include file="adovbs.inc"--> <!--#include file="connection.asp"-->
<% If Request.ServerVariables("Query_String") = "" Then End If %>
<% Dim objConn Dim objRs Dim rsTotalRecords Dim strCount Dim queryString Dim tempQueryString Dim subject Dim author Dim title Dim titleNo Dim message
Dim currentNo Dim currentOrder(10)
Dim mypage Dim mypagesize Dim mySQL Dim maxpages Dim maxrecs Dim howmanyrecs Dim howmanyfields Dim pad Dim scriptname Dim counterstart, counterend, counter Dim ref
%>
<html> <head> <title>Online Library Search</title> </head> <body>
<% '********************************************************** 'allocation of variables '*********************************************************** titleNo = trim(Request.Form("titleNo")) title = trim(Request.Form("title")) author = trim(Request.Form("author")) subject = trim(Request.Form("subject"))
%>
<a href="test.asp">Order Cart</a> <!--Search Form--> <form name="searchfrm" action="testsite.asp" method="post"> <table> <tr><th colspan="2" align="left">Search For: <th></tr> <tr> <td>Title:</td> <td><input type="text" name="title" value="<%=title%>"size="50"></td> </tr> <tr> <td>Author:</td> <td><input type="text" name="author" value="<%=author%>" size="50"></td> </tr> <tr> <td>SUBJ:</td> <td><input type="text" name="subject" value="<%=subject%>" size="50"></td> </tr> <tr> <td><input type="submit" value="Submit"></td> <td><input type="reset" value="Reset"></td> </tr> </table> </form>
<% '************************************************************ 'Write searched Strings to screen '************************************************************ If title <> "" Then Response.Write("Searched Title: " & title & "<br>") End If
If author <> "" Then Response.Write("Searched Author: " & author & "<br>") End If
If subject <> "" Then Response.Write("Searched Subject: " & subject & "<br>") End If %> <br> <% '************************************************* 'validate searched parameters '************************************************* If (subject="") AND (author="") AND (title="") THEN Response.Write("Please enter a search parameter!") Response.End End If %>
<% '******************************** 'Create Query String '********************************
queryString = "SELECT * FROM Internet_Library " strCount = "SELECT COUNT(*) FROM Internet_Library "
If (subject <> "") AND (author <> "") AND (title <> "") Then tempQueryString = tempQueryString & "WHERE Subj LIKE '%" & subject & "%' " tempQueryString = tempQueryString & "AND Author LIKE '%" & author & "%' " tempQueryString = tempQueryString & "AND Title LIKE '%" & title & "%'"
ElseIf (subject <> "") AND (author <> "") AND (title = "") Then tempQueryString = tempQueryString & "WHERE Subj LIKE '%" & subject & "%' " tempQueryString = tempQueryString & "AND Author LIKE '%" & author & "%' "
ElseIf (subject <> "") AND (author = "") AND (title <> "") Then tempQueryString = tempQueryString & "WHERE Subj LIKE '%" & subject & "%' " tempQueryString = tempQueryString & "AND Title LIKE '%" & title & "%'"
ElseIf (subject = "") AND (author <> "") AND (title <> "") Then tempQueryString = tempQueryString & "WHERE Author LIKE '%" & author & "%' " tempQueryString = tempQueryString & "AND Title LIKE '%" & title & "%'"
ElseIf (subject <> "") AND (author = "") AND (title = "") Then tempQueryString = tempQueryString & "WHERE Subj LIKE '%" & subject & "%' "
ElseIf (subject = "") AND (author <> "") AND (title = "") Then tempQueryString = tempQueryString & "WHERE Author LIKE '%" & author & "%' "
ElseIf (subject = "") AND (author = "") AND (title <> "") Then tempQueryString = tempQueryString & "WHERE Title LIKE '%" & title & "%' "
End If
queryString = queryString & tempQueryString strCount = strCount & tempQueryString %>
<% mypage=request("whichpage") IF mypage="" THEN mypage=1 END IF mypagesize=request("pagesize") IF mypagesize="" THEN mypagesize=10 END IF mySQL=request("SQLquery") IF mySQL="" THEN mySQL=queryString END IF %>
<% '********************************* 'open DB connection '********************************* set objRs = Server.CreateObject("ADODB.Recordset") objRs.cursorlocation=aduseclient objRs.CacheSize = 5 objRs.Open queryString, objConn, 3, 3 objRs.movefirst objRs.pagesize=mypagesize maxpages=cint(objRs.pagecount) maxrecs=cint(objRs.pagesize) objRs.absolutepage=mypage howmanyrecs=0 howmanyfields=objRs.fields.count -1
Set rsTotalRecords = objConn.execute(strCount) %>
<% '************************************* 'write found querys to screen '*************************************** response.write "Number of Records found: " & rsTotalRecords(0) & "</br>" response.write "Page " & mypage & " of " & maxpages & "<br>"
DO UNTIL objRs.eof OR howmanyrecs >= maxrecs response.write "<p><table>" response.write "<tr><td><a href='test.asp?ID="&objRs ("titleNo")&"'>order</a></td></tr>" response.write "<tr><td>No: </td><td><a href='detail.asp? ID="&objRs("titleNo")&"'>" & objRs("titleNo") & "</a></td></tr>" response.write "<tr><td>Title: </td><td>" & objRs("Title") & "</td></tr>" response.write "<tr><td>Author: </td><td>" & objRs("Author") & "</td></tr>" response.write "<tr><td>Subject: </td><td>" & objRs("Subj") & "</td></tr>" response.write "</table>" response.write "</p>" objRs.movenext howmanyrecs=howmanyrecs+1 LOOP %>
<% Call PageNavBar %>
<% '***************************************************** 'Procedure for navigation bar as hyperlink '***************************************************** sub PageNavBar() pad=" " scriptname=request.servervariables("script_name") response.write "<table rows='1' cols='1' width='97%'><tr>" response.write "<td>" response.write "<font size='2' color='black' face='Verdana, Arial, Helvetica, sans-serif'>"
if (mypage mod 10) = 0 then counterstart = mypage - 9 else counterstart = mypage - (mypage mod 10) + 1 end if counterend = counterstart + 9
if counterend > maxpages then counterend = maxpages if counterstart <> 1 then ref = "<a href='" & scriptname ref = ref & "?whichpage=" & 1 ref = ref & "&pagesize=" & mypagesize ref = ref & "&sqlQuery=" & server.URLencode(mySQL) ref = ref & "'>First</a> : " Response.write ref
ref = "<a href='" & scriptname ref = ref & "?whichpage=" & (counterstart - 1) ref = ref & "&pagesize=" & mypagesize ref = ref & "&sqlQuery=" & server.URLencode(mySQL) ref = ref & "'>Previous</a> " Response.Write ref end if
Response.Write "[" For counter=counterstart to counterend If counter >= 10 then pad = "" End If
If cstr(counter) <> mypage then ref = "<a href='" & scriptname ref = ref & "?whichpage=" & counter ref = ref & "&pagesize=" & mypagesize ref = ref & "&sqlQuery=" & server.URLencode(mySQL) ref = ref & "'>" & pad & counter & "</a>" Else ref="<b>" & pad & counter & "</b>" End If
response.write ref
If counter <> counterend then response.write " " End If Next Response.Write "]"
If counterend <> maxpages then ref = " <a href='" & scriptname ref = ref & "?whichpage=" & (counterend + 1) ref = ref & "&pagesize=" & mypagesize ref = ref & "&sqlQuery=" & server.URLencode(mySQL) ref = ref & "'>Next</a>" Response.Write ref
ref = " : <a href='" & scriptname ref = ref & "?whichpage=" & maxpages ref = ref & "&pagesize=" & mypagesize ref = ref & "&sqlQuery=" & server.URLencode(mySQL) ref = ref & "'>Last</a>" Response.Write ref End If
response.write "<br></font>" response.write "</td>" response.write "</talbe>" end sub %>
<% '*********************************** 'close DB connection '*********************************** objRS.close rsTotalRecords.close objConn.close Set objRS = Nothing Set rsTotalRecords = Nothing Set objConn = Nothing %> </body> </html>