Results 1 to 3 of 3

Thread: ASP querystring database query

  1. #1
    Senior Member
    Join Date
    Jul 2003
    Location
    Whitley Bay, UK
    Posts
    254
    Thanks
    0
    Thanked
    1 time in 1 post

    ASP querystring database query

    Hi all,

    After some help please with asp pages and query string. I have an access db on my server which I want to be able to query using an A-Z list at top of a page. This is where you click on A (for example) and then the asp page will query the database using 'A' as the driver (eg WHERE field LIKE 'A%' etc)...

    Instead of creating 26 different pages with a slightly different query in each, I'd like to pass a variable from the initial page to a single search asp page and the query takes the variable from the querystring - hope this is making sense!!!

    Basically, I know what I want to do, but not quite sure how to accomplish it.

    My code looks like the below at present:

    <%
    accessdb=server.mappath("\private\Courses.mdb")
    mySQL="SELECT Courses.Company, Courses.[Address 1] FROM Courses WHERE Company LIKE 'A%'"

    strconn="PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE="
    strconn=strconn & accessDB & ";"
    'strconn=strconn & "USER ID=;PASSWORD=;"

    call query2table(mySQL,strconn)
    %>

    Many thanks in advance!

  2. #2
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts
    So basically you want to know how to pass a variable between pages? Really this is the first thing you should have learned how to do before starting on database processing (and understood the difference between get and post).

    What you want is to pass the clicked letter to your search page, and from there execute your sql query, substituting the correct letter in your query string.

    (Please bear in mind there are different ways of acheiving this, this isn't meant to be thourough as there is a horde of information on the net).

    Inside your master page:

    Code:
    <a href="details.asp?letter=a">A</a>
    <a href="details.asp?letter=b">B</a>
    <a href="details.asp?letter=c">C</a>
    'etc etc....
    Inside your details page:

    Code:
    Dim sqlLetter
    
    sqlLetter = CStr(Request("letter"))
    
    'Now use your SQL code and replace the letter constant with the above sqlLetter variable
    All from memory, so if it don't work....
    To err is human. To really foul things up ... you need a computer.

  3. #3
    Senior Member
    Join Date
    Jul 2003
    Location
    Whitley Bay, UK
    Posts
    254
    Thanks
    0
    Thanked
    1 time in 1 post
    Thanks yamangman,

    Code I ended up using was ("course" is variable passed from prev page):

    mySQL="SELECT Courses.Company, Courses.[Address 1] FROM Courses WHERE Company LIKE '" & Request.QueryString("course") & "%'"

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. RMA Query
    By billythewiz in forum SCAN.care@HEXUS
    Replies: 7
    Last Post: 07-11-2006, 05:44 PM
  2. Replies: 4
    Last Post: 18-03-2005, 05:03 PM
  3. Using a switch statement and MySQL database
    By Kezzer in forum Software
    Replies: 2
    Last Post: 15-10-2004, 01:37 PM
  4. Interactive ASP database stuff
    By joshwa in forum Software
    Replies: 8
    Last Post: 31-03-2004, 02:36 PM
  5. Database Query Languages
    By Zathras in forum Software
    Replies: 8
    Last Post: 19-11-2003, 08:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •