19. september 2002 - 14:15
Der er
11 kommentarer og 1 løsning
Paging med ASP
Hej Er der nogle der kan hjælpe mig med at lægge paging på denne side ? <html> <head> <title>Search result</title> <link rel="stylesheet" href="style/style.css" type="text/css"> <script language="JavaScript1.2" src="js/menu.js" type="text/javascript"></script> </head> <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> <table width="600" border="0" cellpadding="0" cellspacing="0" align="center"> <tr> <td width="15"> </td> <td><br> <img src="jpg/logo.jpg" width="280" height="45"></td> <td width="15"> </td> </tr> </table> <table width="600" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="15"> </td> <td bgcolor="CCCCCC" width="524"> <!-- Menu bar. --> <div class="menuBar" style="width:80%; align:center;" ><a class="menuButton" href="#" onClick="return buttonClick(event, 'searchMenu');" onMouseOver="buttonMouseover(event, 'searchMenu');" >Search</a ><a class="menuButton" href="#" onClick="return buttonClick(event, 'listsMenu');" onMouseOver="buttonMouseover(event, 'listsMenu');" >Lists</a ><a class="menuButton" href="#" onClick="return buttonClick(event, 'helpMenu');" onMouseOver="buttonMouseover(event, 'helpMenu');" >Help</a ></div> <!-- Main menus. --> <div id="searchMenu" class="menu" onMouseOver="menuMouseover(event)"> <a class="menuItem" href="quick_search.asp">Quick search</a> <a class="menuItem" href="search.asp">Advanced search</a> </div> <div id="listsMenu" class="menu" onMouseOver="menuMouseover(event)"> <a class="menuItem" href="saleslist.asp">Records for sale</a> <a class="menuItem" href="nosaleslist.asp">Records not for sale</a> <a class="menuItem" href="artists.asp">Artists</a> </div> <div id="helpMenu" class="menu" onMouseOver="menuMouseover(event)"> <a class="menuItem" href="help.asp">Access help</a> <a class="menuItem" href="about.htm">Copyright © 2002</a> </div> <!-- Main menus end. --> </td> <td bgcolor="CCCCCC" width="46"> <div align="right"><a href="#" onClick="window.print();return false">Print</a> </div> </td> <td width="15"> </td> </tr> </table> <table width="600" border="0" cellspacing="0" cellpadding="0" align="center" bgcolor="#FFFFFF" height="100%"> <tr> <td width="15"> </td> <td width="570" valign="top" height="30" colspan="2"><b><br> <br> Result of your search</b><br> <br> <br> </td> <td width="15"> </td> </tr> <tr valign="top"> <td width="15"> </td> <td width="570" colspan="2"> <% Dim strSQL Dim ArtistName, Title, Label, Year, Country, RecordNumber, FormatType, Publication ArtistName = Trim(Replace(Request.Form("ArtistName"), "'", "''")) Title = Trim(Replace(Request.Form("Title"), "'", "''")) Label = Trim(Replace(Request.Form("Label"), "'", "''")) Year = Trim(Replace(Request.Form("Year"), "'", "''")) Country = Trim(Replace(Request.Form("Country"), "'", "''")) RecordNumber = Trim(Replace(Request.Form("RecordNumber"), "'", "''")) FormatType = Trim(Replace(Request.Form("FormatType"), "'", "''")) Publication = Trim(Replace(Request.Form("Publication"), "'", "''")) strSQL = "SELECT ARTIST.ArtistID, ARTIST.ArtistName, COUNTRY.Country, LABEL.Label, RECORD.RecordID, RECORD.Title, RECORD.Year, RECORD.Sale, RECORD.RecordNumber, RECORD.Publication FROM LABEL INNER JOIN (COUNTRY INNER JOIN (RECORD INNER JOIN (ARTIST INNER JOIN ARTIST_RECORD ON ARTIST.ArtistID = ARTIST_RECORD.ArtistID) ON RECORD.RecordID = ARTIST_RECORD.RecordID) ON COUNTRY.CountryID = RECORD.CountryID) ON LABEL.LabelID = RECORD.LabelID WHERE ARTIST.ArtistName LIKE'%" & ArtistName & "%' AND RECORD.Title LIKE'%" & Title & "%' AND LABEL.Label LIKE'%" & Label & "%' AND RECORD.RecordNumber LIKE'%" & RecordNumber & "%' AND RECORD.FormatType LIKE'%" & FormatType & "%' AND RECORD.Publication LIKE'%" & Publication & "%' AND RECORD.Year LIKE'%" & Year & "%' AND COUNTRY.Country LIKE'%" & Country & "%' ORDER BY ARTIST.ArtistName ASC;" Set Conn = Server.CreateObject("ADODB.Connection") DSN = "DRIVER={Microsoft Access Driver (*.mdb)}; " DSN = DSN & "DBQ=" & Server.MapPath ("\recorddatabase\db\recorddatabase.mdb") Conn.Open DSN Set rs = Conn.Execute(strSQL) If Not rs.EOF Then %> <table width="570px" cellspacing=0 cellpadding=4 border=0> <tr bgcolor="BCCADE"> <td width=150 height="30"><b>Artists</b></td> <td width=150 height="30"><b>Title</b></td> <td width=35 height="30"> <div align="center"><b>Year</b></div> </td> <td width=140 height="30"><b>Label</b></td> <td width=60 height="30"><b>Country</b></td> <td width=35 height="30"> <div align="center"><b>Issue</b></div> </td> </tr> <tr bgcolor="#FFFFFF"> <td width=150 height="5"> </td> <td width=150 height="5"> </td> <td width=35 height="5"> <div align="center"></div> </td> <td width=140 height="5"> </td> <td width=55 height="5"> </td> <td width=35 height="5"> </td> </tr> <% Do While Not rs.EOF %> <tr> <td width=150 height="25"><a href="artist_details.asp?id=<%=rs("ArtistID")%>"><%=rs("ArtistName")%></a></td> <td width=150 height="25"><a href="record_details.asp?art=<%=rs("RecordID")%>"><%=rs("Title")%></a></td> <td width=35 height="25"> <div align="center"><%=rs("year")%></div> </td> <td width=140 height="25"><%=rs("label")%> </td> <td width=55 height="25"><%=rs("country")%></td> <td width=35 height="25"> <div align="center"><%=rs("Publication")%></div> </td> </tr> <% rs.MoveNext Loop %> </table> <% Else Response.Write " No records found" End If Conn.Close Set Conn = Nothing %> </td> </tr> </table> <td width="15"> </td> <tr> <td width="15"> </td> <td width="570"> </td> <td width="15"> </td> </tr> </body> </html> Det behøver ikke være en vildt avanceret paging, blot et frem/tilbage-link med 10 records per side. Er helt ny i asp.
Annonceindlæg fra Infor
19. september 2002 - 14:17
#1
19. september 2002 - 14:17
#2
19. september 2002 - 14:18
#3
Jeg synes den på activedeveloper.dk er den bedste, så start med den :)
19. september 2002 - 14:22
#4
Har brug for et direkte eksempel på siden jeg har lagt op
19. september 2002 - 14:22
#5
:)
19. september 2002 - 14:31
#6
Mener du at du gerne vil have mig til at lægge paging på den kode du har skrevet?
19. september 2002 - 14:36
#7
Her er i værtfald et forsøg... sig til hvis du får fejl: <html> <head> <title>Search result</title> <link rel="stylesheet" href="style/style.css" type="text/css"> <script language="JavaScript1.2" src="js/menu.js" type="text/javascript"></script> </head> <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> <table width="600" border="0" cellpadding="0" cellspacing="0" align="center"> <tr> <td width="15"> </td> <td><br> <img src="jpg/logo.jpg" width="280" height="45"></td> <td width="15"> </td> </tr> </table> <table width="600" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="15"> </td> <td bgcolor="CCCCCC" width="524"> <!-- Menu bar. --> <div class="menuBar" style="width:80%; align:center;" ><a class="menuButton" href="#" onClick="return buttonClick(event, 'searchMenu');" onMouseOver="buttonMouseover(event, 'searchMenu');" >Search</a ><a class="menuButton" href="#" onClick="return buttonClick(event, 'listsMenu');" onMouseOver="buttonMouseover(event, 'listsMenu');" >Lists</a ><a class="menuButton" href="#" onClick="return buttonClick(event, 'helpMenu');" onMouseOver="buttonMouseover(event, 'helpMenu');" >Help</a ></div> <!-- Main menus. --> <div id="searchMenu" class="menu" onMouseOver="menuMouseover(event)"> <a class="menuItem" href="quick_search.asp">Quick search</a> <a class="menuItem" href="search.asp">Advanced search</a> </div> <div id="listsMenu" class="menu" onMouseOver="menuMouseover(event)"> <a class="menuItem" href="saleslist.asp">Records for sale</a> <a class="menuItem" href="nosaleslist.asp">Records not for sale</a> <a class="menuItem" href="artists.asp">Artists</a> </div> <div id="helpMenu" class="menu" onMouseOver="menuMouseover(event)"> <a class="menuItem" href="help.asp">Access help</a> <a class="menuItem" href="about.htm">Copyright © 2002</a> </div> <!-- Main menus end. --> </td> <td bgcolor="CCCCCC" width="46"> <div align="right"><a href="#" onClick="window.print();return false">Print</a> </div> </td> <td width="15"> </td> </tr> </table> <table width="600" border="0" cellspacing="0" cellpadding="0" align="center" bgcolor="#FFFFFF" height="100%"> <tr> <td width="15"> </td> <td width="570" valign="top" height="30" colspan="2"><b><br> <br> Result of your search</b><br> <br> <br> </td> <td width="15"> </td> </tr> <tr valign="top"> <td width="15"> </td> <td width="570" colspan="2"> <% Dim strSQL Dim ArtistName, Title, Label, Year, Country, RecordNumber, FormatType, Publication ArtistName = Trim(Replace(Request.Form("ArtistName"), "'", "''")) Title = Trim(Replace(Request.Form("Title"), "'", "''")) Label = Trim(Replace(Request.Form("Label"), "'", "''")) Year = Trim(Replace(Request.Form("Year"), "'", "''")) Country = Trim(Replace(Request.Form("Country"), "'", "''")) RecordNumber = Trim(Replace(Request.Form("RecordNumber"), "'", "''")) FormatType = Trim(Replace(Request.Form("FormatType"), "'", "''")) Publication = Trim(Replace(Request.Form("Publication"), "'", "''")) strSQL = "SELECT ARTIST.ArtistID, ARTIST.ArtistName, COUNTRY.Country, LABEL.Label, RECORD.RecordID, RECORD.Title, RECORD.Year, RECORD.Sale, RECORD.RecordNumber, RECORD.Publication FROM LABEL INNER JOIN (COUNTRY INNER JOIN (RECORD INNER JOIN (ARTIST INNER JOIN ARTIST_RECORD ON ARTIST.ArtistID = ARTIST_RECORD.ArtistID) ON RECORD.RecordID = ARTIST_RECORD.RecordID) ON COUNTRY.CountryID = RECORD.CountryID) ON LABEL.LabelID = RECORD.LabelID WHERE ARTIST.ArtistName LIKE'%" & ArtistName & "%' AND RECORD.Title LIKE'%" & Title & "%' AND LABEL.Label LIKE'%" & Label & "%' AND RECORD.RecordNumber LIKE'%" & RecordNumber & "%' AND RECORD.FormatType LIKE'%" & FormatType & "%' AND RECORD.Publication LIKE'%" & Publication & "%' AND RECORD.Year LIKE'%" & Year & "%' AND COUNTRY.Country LIKE'%" & Country & "%' ORDER BY ARTIST.ArtistName ASC;" Set Conn = Server.CreateObject("ADODB.Connection") DSN = "DRIVER={Microsoft Access Driver (*.mdb)}; " DSN = DSN & "DBQ=" & Server.MapPath ("\recorddatabase\db\recorddatabase.mdb") Conn.Open DSN Set rs = Server.CreateObject("ADODB.Recordset") rs.Open(strSQL), Conn, 1 Dim Side Side = Trim(Request("Side")) If NOT rs.EOF Then If Side = "" Then Side = 1 Elseif Side <= 0 Then Response.Redirect "default.asp" End if Else Side = 0 End if rs.PageSize = 10 If NOT rs.EOF Then rs.AbsolutePage = CLng(Side) Raekke = 0 End if If Not rs.EOF Then %> <table width="570px" cellspacing=0 cellpadding=4 border=0> <tr bgcolor="BCCADE"> <td width=150 height="30"><b>Artists</b></td> <td width=150 height="30"><b>Title</b></td> <td width=35 height="30"> <div align="center"><b>Year</b></div> </td> <td width=140 height="30"><b>Label</b></td> <td width=60 height="30"><b>Country</b></td> <td width=35 height="30"> <div align="center"><b>Issue</b></div> </td> </tr> <tr bgcolor="#FFFFFF"> <td width=150 height="5"> </td> <td width=150 height="5"> </td> <td width=35 height="5"> <div align="center"></div> </td> <td width=140 height="5"> </td> <td width=55 height="5"> </td> <td width=35 height="5"> </td> </tr> <% Do While Not rs.EOF AND Raekke < rs.PageSize %> <tr> <td width=150 height="25"><a href="artist_details.asp?id=<%=rs("ArtistID")%>"><%=rs("ArtistName")%></a></td> <td width=150 height="25"><a href="record_details.asp?art=<%=rs("RecordID")%>"><%=rs("Title")%></a></td> <td width=35 height="25"> <div align="center"><%=rs("year")%></div> </td> <td width=140 height="25"><%=rs("label")%> </td> <td width=55 height="25"><%=rs("country")%></td> <td width=35 height="25"> <div align="center"><%=rs("Publication")%></div> </td> </tr> <% Raekke = Raekke + 1 rs.MoveNext Loop If CLng(Side) > 1 AND CLng(Side) < CLng(rs.PageCount) Then Response.Write "<a href='default.asp?Side=" & Side - 1 & "'><b>Forrige side</b></a> | " Response.Write "<a href='default.asp?Side=" & Side + 1 & "'><b>Næste side</b></a>" Elseif CLng(Side) > 1 Then Response.Write "<a href='default.asp?Side=" & Side - 1 & "'><b>Forrige side</b></a>" Elseif CLng(Side) < CLng(rs.PageCount) Then Response.Write "<a href='default.asp?Side=" & Side + 1 & "'><b>Næste side</b></a>" End If %> </table> <% Else Response.Write " No records found" End If Conn.Close Set Conn = Nothing %> </td> </tr> </table> <td width="15"> </td> <tr> <td width="15"> </td> <td width="570"> </td> <td width="15"> </td> </tr> </body> </html> Du må lige selv sætte dirverse <br>'s ind ik?
19. september 2002 - 15:05
#8
Hej exp-ralle Har forsøgt med koden, og den fungerer fint i begyndelsen. Den viser 10 records, og et næste link, men når jeg klikker linket får jeg en "The page can not be found".
19. september 2002 - 15:08
#9
Ahaaa... det er fordi du skal ændre default.asp til det din side hedder ved alle linier her: If CLng(Side) > 1 AND CLng(Side) < CLng(rs.PageCount) Then Response.Write "<a href='default.asp?Side=" & Side - 1 & "'><b>Forrige side</b></a> | " Response.Write "<a href='default.asp?Side=" & Side + 1 & "'><b>Næste side</b></a>" Elseif CLng(Side) > 1 Then Response.Write "<a href='default.asp?Side=" & Side - 1 & "'><b>Forrige side</b></a>" Elseif CLng(Side) < CLng(rs.PageCount) Then Response.Write "<a href='default.asp?Side=" & Side + 1 & "'><b>Næste side</b></a>" End If
19. september 2002 - 15:13
#10
Eller brug denne kode, den burde virke: <html> <head> <title>Search result</title> <link rel="stylesheet" href="style/style.css" type="text/css"> <script language="JavaScript1.2" src="js/menu.js" type="text/javascript"></script> </head> <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> <table width="600" border="0" cellpadding="0" cellspacing="0" align="center"> <tr> <td width="15"> </td> <td><br> <img src="jpg/logo.jpg" width="280" height="45"></td> <td width="15"> </td> </tr> </table> <table width="600" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="15"> </td> <td bgcolor="CCCCCC" width="524"> <!-- Menu bar. --> <div class="menuBar" style="width:80%; align:center;" ><a class="menuButton" href="#" onClick="return buttonClick(event, 'searchMenu');" onMouseOver="buttonMouseover(event, 'searchMenu');" >Search</a ><a class="menuButton" href="#" onClick="return buttonClick(event, 'listsMenu');" onMouseOver="buttonMouseover(event, 'listsMenu');" >Lists</a ><a class="menuButton" href="#" onClick="return buttonClick(event, 'helpMenu');" onMouseOver="buttonMouseover(event, 'helpMenu');" >Help</a ></div> <!-- Main menus. --> <div id="searchMenu" class="menu" onMouseOver="menuMouseover(event)"> <a class="menuItem" href="quick_search.asp">Quick search</a> <a class="menuItem" href="search.asp">Advanced search</a> </div> <div id="listsMenu" class="menu" onMouseOver="menuMouseover(event)"> <a class="menuItem" href="saleslist.asp">Records for sale</a> <a class="menuItem" href="nosaleslist.asp">Records not for sale</a> <a class="menuItem" href="artists.asp">Artists</a> </div> <div id="helpMenu" class="menu" onMouseOver="menuMouseover(event)"> <a class="menuItem" href="help.asp">Access help</a> <a class="menuItem" href="about.htm">Copyright © 2002</a> </div> <!-- Main menus end. --> </td> <td bgcolor="CCCCCC" width="46"> <div align="right"><a href="#" onClick="window.print();return false">Print</a> </div> </td> <td width="15"> </td> </tr> </table> <table width="600" border="0" cellspacing="0" cellpadding="0" align="center" bgcolor="#FFFFFF" height="100%"> <tr> <td width="15"> </td> <td width="570" valign="top" height="30" colspan="2"><b><br> <br> Result of your search</b><br> <br> <br> </td> <td width="15"> </td> </tr> <tr valign="top"> <td width="15"> </td> <td width="570" colspan="2"> <% Dim strSQL Dim ArtistName, Title, Label, Year, Country, RecordNumber, FormatType, Publication ArtistName = Trim(Replace(Request.Form("ArtistName"), "'", "''")) Title = Trim(Replace(Request.Form("Title"), "'", "''")) Label = Trim(Replace(Request.Form("Label"), "'", "''")) Year = Trim(Replace(Request.Form("Year"), "'", "''")) Country = Trim(Replace(Request.Form("Country"), "'", "''")) RecordNumber = Trim(Replace(Request.Form("RecordNumber"), "'", "''")) FormatType = Trim(Replace(Request.Form("FormatType"), "'", "''")) Publication = Trim(Replace(Request.Form("Publication"), "'", "''")) strSQL = "SELECT ARTIST.ArtistID, ARTIST.ArtistName, COUNTRY.Country, LABEL.Label, RECORD.RecordID, RECORD.Title, RECORD.Year, RECORD.Sale, RECORD.RecordNumber, RECORD.Publication FROM LABEL INNER JOIN (COUNTRY INNER JOIN (RECORD INNER JOIN (ARTIST INNER JOIN ARTIST_RECORD ON ARTIST.ArtistID = ARTIST_RECORD.ArtistID) ON RECORD.RecordID = ARTIST_RECORD.RecordID) ON COUNTRY.CountryID = RECORD.CountryID) ON LABEL.LabelID = RECORD.LabelID WHERE ARTIST.ArtistName LIKE'%" & ArtistName & "%' AND RECORD.Title LIKE'%" & Title & "%' AND LABEL.Label LIKE'%" & Label & "%' AND RECORD.RecordNumber LIKE'%" & RecordNumber & "%' AND RECORD.FormatType LIKE'%" & FormatType & "%' AND RECORD.Publication LIKE'%" & Publication & "%' AND RECORD.Year LIKE'%" & Year & "%' AND COUNTRY.Country LIKE'%" & Country & "%' ORDER BY ARTIST.ArtistName ASC;" Set Conn = Server.CreateObject("ADODB.Connection") DSN = "DRIVER={Microsoft Access Driver (*.mdb)}; " DSN = DSN & "DBQ=" & Server.MapPath ("\recorddatabase\db\recorddatabase.mdb") Conn.Open DSN Set rs = Server.CreateObject("ADODB.Recordset") rs.Open(strSQL), Conn, 1 Dim Side Side = Trim(Request("Side")) If NOT rs.EOF Then If Side = "" Then Side = 1 Elseif Side <= 0 Then Response.Redirect "<a href='" & Request.ServerVariables("SCRIPT_NAME") & "?Side=" End if Else Side = 0 End if rs.PageSize = 10 If NOT rs.EOF Then rs.AbsolutePage = CLng(Side) Raekke = 0 End if If Not rs.EOF Then %> <table width="570px" cellspacing=0 cellpadding=4 border=0> <tr bgcolor="BCCADE"> <td width=150 height="30"><b>Artists</b></td> <td width=150 height="30"><b>Title</b></td> <td width=35 height="30"> <div align="center"><b>Year</b></div> </td> <td width=140 height="30"><b>Label</b></td> <td width=60 height="30"><b>Country</b></td> <td width=35 height="30"> <div align="center"><b>Issue</b></div> </td> </tr> <tr bgcolor="#FFFFFF"> <td width=150 height="5"> </td> <td width=150 height="5"> </td> <td width=35 height="5"> <div align="center"></div> </td> <td width=140 height="5"> </td> <td width=55 height="5"> </td> <td width=35 height="5"> </td> </tr> <% Do While Not rs.EOF AND Raekke < rs.PageSize %> <tr> <td width=150 height="25"><a href="artist_details.asp?id=<%=rs("ArtistID")%>"><%=rs("ArtistName")%></a></td> <td width=150 height="25"><a href="record_details.asp?art=<%=rs("RecordID")%>"><%=rs("Title")%></a></td> <td width=35 height="25"> <div align="center"><%=rs("year")%></div> </td> <td width=140 height="25"><%=rs("label")%> </td> <td width=55 height="25"><%=rs("country")%></td> <td width=35 height="25"> <div align="center"><%=rs("Publication")%></div> </td> </tr> <% Raekke = Raekke + 1 rs.MoveNext Loop If CLng(Side) > 1 AND CLng(Side) < CLng(rs.PageCount) Then Response.Write "<a href='" & Request.ServerVariables("SCRIPT_NAME") & "?Side=" & Side - 1 & "'><b>Forrige side</b></a> | " Response.Write "<a href='" & Request.ServerVariables("SCRIPT_NAME") & "?Side=" & Side + 1 & "'><b>Næste side</b></a>" Elseif CLng(Side) > 1 Then Response.Write "<a href='" & Request.ServerVariables("SCRIPT_NAME") & "?Side=" & Side - 1 & "'><b>Forrige side</b></a>" Elseif CLng(Side) < CLng(rs.PageCount) Then Response.Write "<a href='" & Request.ServerVariables("SCRIPT_NAME") & "?Side=" & Side + 1 & "'><b>Næste side</b></a>" End If %> </table> <% Else Response.Write " No records found" End If Conn.Close Set Conn = Nothing %> </td> </tr> </table> <td width="15"> </td> <tr> <td width="15"> </td> <td width="570"> </td> <td width="15"> </td> </tr> </body> </html>
19. september 2002 - 15:14
#11
Det er KANON. 1000 tak for hjælpen. Hilsen Thomas
19. september 2002 - 15:16
#12
Så lidt. Tak for point.
Kurser inden for grundlæggende programmering