Selecting database records using the QueryString

This is a discussion on "Selecting database records using the QueryString" within the Classic ASP section. This forum, and the thread "Selecting database records using the QueryString are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > Classic ASP

Notices


Closed Thread
 
LinkBack Thread Tools
  #1 (permalink)  
Old Aug 25th, 2004, 14:55
Highly Reputable Member
Join Date: Aug 2003
Location: Australia
Posts: 662
Thanks: 0
Thanked 0 Times in 0 Posts
Selecting database records using the QueryString

Ok, can anyone please explain this to me . Hey Smokie, I used the Exact title . thanks for your help guys.

  #2 (permalink)  
Old Aug 25th, 2004, 22:55
Most Reputable Member
Join Date: Jul 2003
Posts: 1,856
Thanks: 0
Thanked 0 Times in 0 Posts
sSQL = "SELECT whatever FROM wherever WHERE userid=" & request.querystring("id")

mypage.asp?id=5
  #3 (permalink)  
Old Aug 26th, 2004, 08:07
Highly Reputable Member
Join Date: Jul 2003
Location: Ipswich, UK
Posts: 690
Thanks: 0
Thanked 0 Times in 0 Posts
thats it Court Jester
  #4 (permalink)  
Old Aug 26th, 2004, 12:56
Highly Reputable Member
Join Date: Aug 2003
Location: Australia
Posts: 662
Thanks: 0
Thanked 0 Times in 0 Posts
ok, I see the code, but how do I get that to work for me? Where do I place that code? Does it go as a part of my link? Still confused.. thanks.
  #5 (permalink)  
Old Aug 26th, 2004, 13:09
Rob's Avatar
Rob Rob is offline
Head Admin & CEO

SuperMember
Join Date: Jul 2003
Location: at my desk
Age: 34
Posts: 2,952
Blog Entries: 7
Thanks: 7
Thanked 4 Times in 4 Posts
Send a message via MSN to Rob Send a message via Skype™ to Rob
Court Jester... you really have answered your own question here in your initial post.

You include the ID of the item you want from the database in your link (as a querystring)... eg:- mypage.asp?id=272

and then use the SQL select statement you posted to get at the element in the db who's id matches. you can pull whatever data you need to from the database (i know you know how to do that, so wont go into it) and display it.
__________________
Rob - SEO Specialist
Owner & Founder of Webforumz.com

I am currently unavailable for private work
  #6 (permalink)  
Old Aug 26th, 2004, 13:38
Highly Reputable Member
Join Date: Jul 2003
Location: Ipswich, UK
Posts: 690
Thanks: 0
Thanked 0 Times in 0 Posts
for example:

Code: Select all
Set objRS = objConn.Execute("SELECT [ID],[Title] FROM table")
If objRS.EOF Then
  Response.Write "no records"
Else
  Do While Not objRS.EOF
    Response.Write "<a href=details.asp?ID="&objRS("ID")&">"&objRS("Title")&"</a>
"
  objRS.MoveNext
  Loop
End If
objRS.Close
Set objRS = Nothing
The above will create something like this:

Code: Select all
<a href=details.asp?ID=1>Mr Smith</a>

<a href=details.asp?ID=2>Mrs Jones</a>

<a href=details.asp?ID=3>Mr Small</a>

<a href=details.asp?ID=4>Mrs West</a>
Does that help?
  #7 (permalink)  
Old Aug 26th, 2004, 15:35
Highly Reputable Member
Join Date: Aug 2003
Location: Australia
Posts: 662
Thanks: 0
Thanked 0 Times in 0 Posts
COOL! Thanks Rob for taking the confusion away . Thanks Smokie, that's a big help as well, This totally rocks!
  #8 (permalink)  
Old Aug 27th, 2004, 03:39
Highly Reputable Member
Join Date: Aug 2003
Location: Australia
Posts: 662
Thanks: 0
Thanked 0 Times in 0 Posts
hrmmm I tried the code you gave me smokie, and while I understand what it does and all.. the way you did it is a lot different then I normally do it. I am getting an error on line 16 which is this:
Code: Select all
Set objRS = objConn.Execute("SELECT [ID],[PageName] FROM Page")
and here's the entire thing...
Code: Select all
<% Set connectionToDatabase=Server.CreateObject("ADODB.Connection")
connectionToDatabase.ConnectionTimeout=60
connectionToDatabase.Open "DSN=Mydatabase"

dim objRS
dim objConn
objRS = recordSet
objConn = connectionToDatabase

Set objRS = objConn.Execute("SELECT [ID],[PageName] FROM Page")
If objRS.EOF Then
  Response.Write "no records"
Else
  Do While Not objRS.EOF
    Response.Write "<a href=details.asp?ID="&objRS("ID")&">"&objRS("PageName")&"</a>"
  objRS.MoveNext
  Loop
End If
objConn.Close
Set objConn = Nothing
%>
thanks for your help

ohhh and this is the error....
Microsoft VBScript runtime error '800a01a8'

Object required: 'Provider=MSDASQL.1;E'

/tests/querystrings.asp, line 16
  #9 (permalink)  
Old Aug 27th, 2004, 09:15
Highly Reputable Member
Join Date: Jul 2003
Location: Ipswich, UK
Posts: 690
Thanks: 0
Thanked 0 Times in 0 Posts
try this:

Code: Select all
<%
Set objConn=Server.CreateObject("ADODB.Connection")
objConn.ConnectionTimeout=60
objConn.Open "DSN=Mydatabase"

Set objRS = objConn.Execute("SELECT [ID],[PageName] FROM Page")
If objRS.EOF Then
  Response.Write "no records"
Else
  Do While Not objRS.EOF
    Response.Write "<a href=details.asp?ID="&objRS("ID")&">"&objRS("PageName")&"&lt/a>"
  objRS.MoveNext
  Loop
End If
objConn.Close
Set objConn = Nothing
%>
  #10 (permalink)  
Old Aug 27th, 2004, 15:30
Highly Reputable Member
Join Date: Aug 2003
Location: Australia
Posts: 662
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks a ton Smokie. It works great! Thanks so much for your help!
  #11 (permalink)  
Old Aug 27th, 2004, 19:52
Highly Reputable Member
Join Date: Aug 2003
Location: Australia
Posts: 662
Thanks: 0
Thanked 0 Times in 0 Posts
Ohhh here is my first test at this :wink:.

www.haeglodesigns.com/tests/querystrings.asp
Closed Thread

Tags
selecting, database, records, using, querystring

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing wildcards in a querystring jayaime Classic ASP 0 Oct 11th, 2006 19:02
var = Request.QueryString(item) - why doesn't this work?! Donny Bahama Classic ASP 7 Jun 17th, 2006 08:43
Selecting Numbers WillisTi Flash & Multimedia Forum 1 Nov 16th, 2005 16:56
request.querystring breeze76 Classic ASP 5 Oct 16th, 2005 14:35
PLEASE HELP - Passing Variables in Querystring just_the_basix Classic ASP 40 Sep 3rd, 2004 10:46


All times are GMT. The time now is 15:34.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43