Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP-DB-Re-

Status
Not open for further replies.

Altavista

Programmer
Nov 22, 2002
9
US
Altavista (Visitor) Nov 23, 2000
I am doing a online shoping system. in that,
When user clicks SEARCH Option, i am retriving data in a loop from Database until Recordset.eof, i am displaying some details using table. Normally i am displaying more than 20 records at a time.

1) I need to display only five records in a page, and need to diaply 1-5, 6-10, 11-15, 16-20, .... when the user clicks the above option, i need to display details for that particular number.


2) I need to display More Details when the user clicks a BUTTON in next page for that particular RECORD.



My Question is : How to do it, i am not well in all these concepts.

Regards,
Murugesan
 
This can be a start for you to build on:

The following code assumes:
1. Your asp page is named test.asp.
2. you have a database in a folder called db which is located in the folder where your asp page is (ie if your asp page is in c:\inetpub\wwwroot\asp_page\test.asp, your database should be in c:\inetpub\wwwroot\asp_page\db) and that the name of the database is db1.mdb.
3. There is a table in the database called Table1.
4. The fields in this table include ID, Description

Put the following code into the body of the asp page:

<%
Dim sConString, con, rs, lGroup, sSql
sConString = &quot;Data Source=&quot; & Server.Mappath(&quot;db/db1.mdb&quot;) & &quot;;Provider=Microsoft.Jet.OLEDB.4.0;&quot;
set con = server.CreateObject(&quot;ADODB.Connection&quot;)
con.Open sConString
set rs = Server.CreateObject(&quot;ADODB.Recordset&quot;)
If IsNull(Request.QueryString(&quot;Group&quot;)) OR Request.QueryString(&quot;Group&quot;) = 0 Then
lGroup = 1
Else
lGroup = Request.QueryString(&quot;Group&quot;)
End If
If lGroup = 1 Then
sSql = &quot;SELECT TOP 5 ID, Description FROM Table1 ORDER BY ID&quot;
Else
sSql = &quot;SELECT TOP 5 ID, Description FROM Table1 WHERE ID NOT IN (SELECT TOP &quot; & (lGroup-1)*5 & &quot; ID FROM Table1 ORDER BY ID) ORDER BY ID&quot;
End If
rs.Open sSql, con

Do Until rs.EOF
Response.Write &quot;Item &quot; & rs(&quot;ID&quot;) & &quot;<BR>&quot;
rs.MoveNext
Loop

rs.Close
con.Close
%>
<BR><BR>
<a href=&quot;test.asp?Group=<%=lGroup+1%>&quot;>Next</a>


This script does not deal with things like having a Next option when you have reached the end of the records in the table, but as I said at the top, it should be a start for you.

If you want to extend this and have links to individual items, then make the line

Response.Write &quot;Item &quot; & rs(&quot;ID&quot;) & &quot;<BR>&quot;

write out an <a> tag, passing the ID of the item in the URL and then in the response page you can show just that one item (by using &quot;WHERE ID=&quot; & Request.QueryString(&quot;ID&quot;) on your sql statement to retrieve the correct record.)


Simon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top