Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 9th, 2004, 12:28 PM
Friend of Wrox
Points: 1,107, Level: 13
Points: 1,107, Level: 13 Points: 1,107, Level: 13 Points: 1,107, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2004
Location: , , .
Posts: 240
Thanks: 0
Thanked 1 Time in 1 Post
Default how to add checkboxes in this asp

It seems that my previous posting didn't go through. Oh well.

I decided to restart working from the sample code. It only has one field to search into. So I replaced that with my database "kjv.mdb", table "bible" and field: "text_data" and here is the code:
Code:
<%
'************************************************************************************
'* ADO Recordset Paging Sample Script
'* by Konstantin Vasserman
'* June 2000
'************************************************************************************

Option Explicit

'************************************************************************************
'* Declaration section
'************************************************************************************
' Mode contstants
Const MODE_DEFAULT     = 1
Const MODE_RESULTS     = 2

Const DB_NAME        = "kjv.mdb"    ' Name of our database file
Const SCRIPT_NAME    = "bible5.asp"    ' Name of this script

Const RECORDS_PER_PAGE     = 50            ' Number of records per page

Dim nMode    ' Current Mode
'************************************************************************************
'* End of Declaration section
'************************************************************************************

'************************************************************************************
'* Main section
'************************************************************************************

' Find out what mode we are in
nMode = CLng(Request.QueryString("Mode"))

' Depending on our mode we will do different things
Select Case nMode

    Case MODE_RESULTS
        ' This is where all the results will show        
        ShowResults

    Case Else     ' This one is for MODE_DEFAULT or invalid modes all the same
        ' By default display the search form
        ShowSearchForm    
End Select

'************************************************************************************
'* End of Main section
'************************************************************************************

'************************************************************************************
'* Functions section
'************************************************************************************

' This function will generate our connection string
' it assumes that Access database is in the same folder as this script
Private Function GetConnectionString()
    GetConnectionString =     "Driver={Microsoft Access Driver (*.mdb)};" & _
                "DBQ=" & Server.MapPath(DB_NAME) & ";" & _
                "UID=;PWD=;"
End Function

' Shows HTML page header 
Public Function OutputPageHeader()
    %>
    <HTML>
    <HEAD><TITLE>ADO Recordset Paging Sample</TITLE></HEAD>
    <BODY>
    <H2>ADO Recordset Paging Sample</H2>
    <H3><A HREF="<%=SCRIPT_NAME%>">Back Home</A></H3>
    <%
End Function

' Shows HTML page footer 
Public Function OutputPageFooter()
    %>
    </BODY>
    </HTML>
    <%
End Function

' This function will display the search form
Private Function ShowSearchForm()
    OutputPageHeader
    %>
    <!--
        This form will direct user to itself with MODE_RESULTS mode
    -->
    <FORM ACTION="<%=SCRIPT_NAME%>" METHOD="GET">
    Item Name: <INPUT TYPE="text" NAME="Keyword" VALUE="Item"> <INPUT TYPE="submit" VALUE=" Search ">
    <INPUT TYPE="hidden" NAME="Mode" VALUE="<%=MODE_RESULTS%>">
    </FORM>
    <%
    OutputPageFooter
End Function

' This function will display the results of the search
Private Function ShowResults()
    Dim strConn    ' Database connection string
    Dim SQL     ' String that will have our SQL statments
    Dim RS        ' Recordset object
    Dim Keyword    ' Keyword for search
    Dim nRecCount    ' Number of records found
    Dim nPageCount    ' Number of pages of records we have
    Dim nPage    ' Current page number

    ' Let's see what page are we looking at right now
    nPage = CLng(Request.QueryString("Page"))

    ' Let's see what user wants to search for today :)
    Keyword = Trim(Request.QueryString("Keyword"))

    ' define our SQL statment
    ' we will be looking for all the records in tblItem table 
    ' where ItemName contains our Keyword
    ' do not forget to fix tick marks (single quotes) in our Keyword
    SQL = "SELECT * FROM bible WHERE text_data LIKE '%" & Replace(Keyword, "'", "''") & "%'"

    ' Create our connection string
    strConn = GetConnectionString()

    ' Time to create and open recordset
    Set RS = Server.CreateObject("ADODB.Recordset")
    RS.CursorLocation = 3 ' adUseClient
    RS.Open SQL, strConn ' adOpenKeyset CursorType

    ' Start outputing HTML
    OutputPageHeader

    ' Did we find anything?
    If Not RS.Eof Then
        ' Let's deal with our findings

        ' Get records count
        nRecCount = RS.RecordCount

        ' Tell recordset to split records in the pages of our size
        RS.PageSize = RECORDS_PER_PAGE

        ' How many pages we've got
        nPageCount = RS.PageCount

        ' Make sure that the Page parameter passed to us is within the range
        If nPage < 1 Or nPage > nPageCount Then
            ' Ops - bad page number
            ' let's fix it
            nPage = 1            
        End If

        ' Time to tell user what we've got so far
        Response.Write nRecCount & " records found matching """ & Keyword & """.<br>"
        Response.Write nPageCount & " pages of results.<br>"
        Response.Write "Current page is " & nPage & ".<p>"

        ' Give user some navigation

        ' first page
        ' we link to this page with Page parameter = 1
        Response.Write     "<A HREF=""" & SCRIPT_NAME & _
                "?Keyword=" & Keyword & _
                "&Mode=" & MODE_RESULTS & _
                "&Page=" & 1 & _
                """>First Page</A>"
        Response.Write "&nbsp;&nbsp;&nbsp;&nbsp;"

        ' Previous Page
        ' we link to this page with Page parameter = Current Page - 1
        Response.Write     "<A HREF=""" & SCRIPT_NAME & _
                "?Keyword=" & Keyword & _
                "&Mode=" & MODE_RESULTS & _
                "&Page=" & nPage - 1 & _
                """>Prev. Page</A>"
        Response.Write "&nbsp;&nbsp;&nbsp;&nbsp;"

        ' Next Page
        ' we link to this page with Page parameter Current Page + 1
        Response.Write     "<A HREF=""" & SCRIPT_NAME & _
                "?Keyword=" & Keyword & _
                "&Mode=" & MODE_RESULTS & _
                "&Page=" & nPage + 1 & _
                """>Next Page</A>"
        Response.Write "&nbsp;&nbsp;&nbsp;&nbsp;"

        ' Last Page
        ' we link to this page with Page parameter = nPageCount
        Response.Write     "<A HREF=""" & SCRIPT_NAME & _
                "?Keyword=" & Keyword & _
                "&Mode=" & MODE_RESULTS & _
                "&Page=" & nPageCount & _
                """>Last Page</A>"

        ' Start Results
        Response.Write "<p><b>Results:</b><br>" & String(20,"-")

        ' Position recordset to the page we want to see
        RS.AbsolutePage = nPage

        ' Let's output our records                
        ' Loop through records until it's a next page or End of Records
        Do While Not (RS.Eof OR RS.AbsolutePage <> nPage)

            ' All we do here is just show the records
            Response.Write "<br>" & RS("text_data")

            ' Move on to the next record
            RS.MoveNext
        Loop
    Else
        ' We did not find anything
        Response.Write "Nothing found. Try again.<p><A HREF=""" & SCRIPT_NAME & """>Back</A>"
    End If

    ' Be nice - close the recordset
    RS.Close

    ' Finish this page
    OutputPageFooter
End Function
'************************************************************************************
'* End of Functions section
'************************************************************************************
%>
I need to change this into a multiple field search, where I can enable/disable by using checkboxes. I have the oringinal codes for checkbox functions used in another page format. I just need to adjust to this page format. I will post more later.

Reply With Quote
  #2 (permalink)  
Old August 10th, 2004, 12:17 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

This is being answered in another thread. select from 66 tables using checkboxes - how

Please don't reply to this.

_________________________
- Vijay G
Strive for Perfection
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
treeview control with checkboxes in asp.net 1.1 sandeep_345 General .NET 0 June 9th, 2006 01:56 AM
How do i add checkboxes on Flexgrid ? leo_vinay VB How-To 18 March 8th, 2006 08:04 AM
Add asp.net page to asp project debdemoe Classic ASP Basics 0 August 17th, 2005 12:28 PM
Deleting several records on ASP using checkboxes luisbueno Oracle ASP 1 April 25th, 2005 08:47 PM
asp add crmpicco Classic ASP Databases 2 March 4th, 2005 10:34 AM



All times are GMT -4. The time now is 09:28 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.