SunQuest
           ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old September 29th, 2003, 07:01 PM
Tyssen Tyssen is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Brisbane
Posts: 129 Tyssen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 31 m 55 sec
Reputation Power: 5
Passing value from one query to another

I'm creating a product display page on which I want to include a box featuring the most recent product in the subject of the product featured.
The product ID is passed in from the URL, and I'm trying to take the subject of that product and display its most recent title.
Here's my code: all I get at the moment is the same product on every single page, regardless of what product ID is passed in.

<%
productID=Request.Querystring("pID")
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("/xxx.mdb")
sql = "SELECT kbs.subject FROM kbs WHERE id = " & productID & ";"
set rs = Server.CreateObject("ADODB.Recordset")
set rs = conn.execute(sql2)
subj = ("kbs.subject")
sql2 = "SELECT * FROM kbs, media where kbs.media=media.mediaTypeID AND kbs.subject = " & subj & " ORDER BY publicationDate desc;"
set rs2 = Server.CreateObject("ADODB.Recordset")
set rs2 = conn.execute(sql2)
%>

Any ideas?

Reply With Quote
  #2  
Old September 30th, 2003, 01:15 AM
nopoints nopoints is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Windsor ON, Canada
Posts: 459 nopoints User rank is Corporal (100 - 500 Reputation Level)nopoints User rank is Corporal (100 - 500 Reputation Level)nopoints User rank is Corporal (100 - 500 Reputation Level)nopoints User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 13 h 44 m 22 sec
Reputation Power: 8
what is subj = ("kbs.subject") suppose to do?
__________________
Programmer's Corner

Reply With Quote
  #3  
Old September 30th, 2003, 01:34 AM
Tyssen Tyssen is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Brisbane
Posts: 129 Tyssen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 31 m 55 sec
Reputation Power: 5
Quote:
Originally posted by nopoints
what is subj = ("kbs.subject") supposed to do?


I thought I needed to create a new variable that was set to be kbs.subject of the first query and then to run a query based on that variable.

I dunno really - I'm pretty new to this stuff and I'm working with code that was written before I took on this project, so I'm just trying to work it out as I go along.

Reply With Quote
  #4  
Old September 30th, 2003, 01:38 AM
nopoints nopoints is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Windsor ON, Canada
Posts: 459 nopoints User rank is Corporal (100 - 500 Reputation Level)nopoints User rank is Corporal (100 - 500 Reputation Level)nopoints User rank is Corporal (100 - 500 Reputation Level)nopoints User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 13 h 44 m 22 sec
Reputation Power: 8
i think what you want is:
Code:
subj = rs("kbs.subject")

what your previous code is doing is setting sub to the string kbs.subject. then in your where clause you have where kbs.subject = kbs.subject which is always true

Reply With Quote
  #5  
Old September 30th, 2003, 01:47 AM
Tyssen Tyssen is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Brisbane
Posts: 129 Tyssen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 31 m 55 sec
Reputation Power: 5
Quote:
Originally posted by nopoints
i think what you want is:
Code:
subj = rs("kbs.subject")

I tried that before: I get a Type mismatch: 'rs' error message when I do that.

Reply With Quote
  #6  
Old September 30th, 2003, 02:32 AM
pda8333 pda8333 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 216 pda8333 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 6 m 31 sec
Reputation Power: 5
could it be like this

Code:
<%
:
set rs = Server.CreateObject("ADODB.Recordset") 
set rs = conn.execute(sql) ' line 7
subj = rs("kbs.subject") ' line 8
:
%>

could be your typo error.

probably your Type mismatch : 'rs' occurs/appears cuz you did not have any "Select...." statement, and that leads to your line 7.

if i'm wrong, pls let us know.

Reply With Quote
  #7  
Old September 30th, 2003, 04:57 PM
Tyssen Tyssen is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Brisbane
Posts: 129 Tyssen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 31 m 55 sec
Reputation Power: 5
Now I get:

Item cannot be found in the collection corresponding to the requested name or ordinal.

/education/featprod3.asp, line 20


which is this line: subj = rs("kbs.subject")

Does that mean it can't find the variable 'subj' in my query?

PS: Fixed up 'sql2' typo.

Reply With Quote
  #8  
Old October 2nd, 2003, 12:38 AM
pda8333 pda8333 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 216 pda8333 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 6 m 31 sec
Reputation Power: 5
if this is the error line, then that means your 'id' does not exist.

or you could try this, remove your kbs. from the subject
Code:
subj = rs("subject")

Last edited by pda8333 : October 2nd, 2003 at 12:51 AM.

Reply With Quote
  #9  
Old October 5th, 2003, 08:30 PM
Tyssen Tyssen is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Brisbane
Posts: 129 Tyssen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 31 m 55 sec
Reputation Power: 5
For anyone that's interested, with help from someone I finally got it to work using this:

sql = "SELECT kbs.subject FROM kbs WHERE id = " & productID & ";"
set rs = Server.CreateObject("ADODB.Recordset")
set rs = conn.execute(sql)
subj = rs.fields.item(0)
sql2 = "SELECT * FROM kbs, media where kbs.media=media.mediaTypeID AND kbs.subject = " & subj & " ORDER BY publicationDate desc;"
set rs2 = Server.CreateObject("ADODB.Recordset")
set rs2 = conn.execute(sql2)

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > Passing value from one query to another


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway