Forums

This topic is locked

Recordset value to variable: HOW?

Posted 27 Jan 2005 21:55:34
1
has voted
27 Jan 2005 21:55:34 Simon Bloodworth posted:
All i want to do is have a value from a recordset set to a variable so that i can call this variable from an include file. Im sue

<%
Dim objValue1
objValue1 = recordset1.fields.item("filed1".value

%>

but keep getting the error : objext required.

Aaahhhh! Its driving me crazy.

Any help would be greatly appreciated.

Regards

Replies

Replied 27 Jan 2005 22:32:37
27 Jan 2005 22:32:37 Simon Martin replied:
Ahhh... this is a real bugger
Trouble is in the order in which the page is processed and guess what... includes are included <i>before</i> server side scripting goes on
Good article this one - www.asp101.com/articles/michael/dynamicincludes/default.asp

Live the life you love
Love the life you live

Simon
Replied 27 Jan 2005 22:50:53
27 Jan 2005 22:50:53 Simon Bloodworth replied:
A great help. Thankyou.
Replied 28 Jan 2005 10:51:33
28 Jan 2005 10:51:33 Simon Bloodworth replied:
Ahhh! Cant get it to work.

What i do:

On my store every time someone on a visit looks at products, that product gets entered into a database along with the sessionID so that one customers visit is logged. Fine - do this no problem.

Where i am now is trying to have on the product view something like - ' people who looked at this also looked at this '

The idea was to query the database with the id of the product being viewed then display the other products associated with it by the sessionID. Does that make sense? To acheive this i had an include file which called a form element for product id and put it into a string so that i could use that value on the main product view page.

I just cant get it to work!

Any help would be greatly received
Replied 28 Jan 2005 11:09:16
28 Jan 2005 11:09:16 Lee Diggins replied:
Hi Simon

Post your code and any errors.

Simon Martin&gt;&gt; Well found that man, bit different to the select case dynamic includes wouldn't you say. Have you implemeted this anywhere yet?

Digga

Sharing Knowledge Saves Valuable Time!!!
Replied 28 Jan 2005 11:20:06
28 Jan 2005 11:20:06 Simon Bloodworth replied:
Dont have any errors as such just great big brick walls that i cant seem to get around!!!

For the life of me i just cant think how to do it!
Replied 28 Jan 2005 12:24:15
28 Jan 2005 12:24:15 Lee Diggins replied:
A bit stumped then Simon, a bit difficult to suggest what to do next, try it with the code on the page rather than in the include maybe.

Post your code then buddy.

Digga

Sharing Knowledge Saves Valuable Time!!!
Replied 28 Jan 2005 12:39:26
28 Jan 2005 12:39:26 Simon Bloodworth replied:
Hi Lee,

Right. Here goes:

My include file: tracker_pick.asp ;

&lt;%
Dim objProductViewed
objproductViewed = Rs_Track.Fields.Item("ID_User".Value
%&gt;

&lt;%
Dim Rs_Track__VarTrack
Rs_Track__VarTrack = "%"
If (request.querystring("pid" &lt;&gt; "" Then
Rs_Track__VarTrack = request.querystring("pid"
End If
%&gt;
&lt;%
Dim Rs_Track
Dim Rs_Track_numRows

Set Rs_Track = Server.CreateObject("ADODB.Recordset"
Rs_Track.ActiveConnection = MM_con_products_STRING
Rs_Track.Source = "SELECT top 1 ID_User FROM Tbl_Tracking WHERE ID_ProductRef = '" + Replace(Rs_Track__VarTrack, "'", "''" + "'"
Rs_Track.CursorType = 0
Rs_Track.CursorLocation = 2
Rs_Track.LockType = 1
Rs_Track.Open()

Rs_Track_numRows = 0
%&gt;

&lt;%
Rs_Track.Close()
Set Rs_Track = Nothing
%&gt;


Code on product view page calling include file using getfilecontents function:

' put the file into the variable
&lt;% Dim strIncludeFile
strIncludeFile = ("../tracker_pick.asp"
%&gt;

' run the file
&lt;% Function getFileContents (strIncludeFile)
Dim objFSO
Dim objText
Dim strPage

Set objFSO = Server.CreateObject("Scripting.FileSystemObject"

Set objText = objFSO.OpenTextFile(strIncludeFile)

getFileContents = objText.ReadAll

objText.Close
Set objText = nothing
Set objFSO = nothing
End Function
%&gt;

' put result of query into string
&lt;%
Dim strMain
strMain = getFileContents("../tracker_pick.inc"
%&gt;

this is what i have at the moment but when i ry and run the product page nothing happens and it just times out?

Thanks for taking the time to help as i expect you have better things to be doing:

Regards

Simon
Replied 28 Jan 2005 15:04:50
28 Jan 2005 15:04:50 Lee Diggins replied:
Hi Simon

Just a quick look, the first statement in your include is causing the error:

&lt;%
Dim objProductViewed
objproductViewed = Rs_Track.Fields.Item("ID_User".Value
%&gt;

You're trying to assign a value to objProductViewed before the recordset has been created, move the assignment after the recordset creation and before the recordset.close statement.

Digga

Sharing Knowledge Saves Valuable Time!!!
Replied 28 Jan 2005 16:53:20
28 Jan 2005 16:53:20 Simon Martin replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>Well found that man, bit different to the select case dynamic includes wouldn't you say <hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
Yeah I posted the link because of the background info it gave on the cause of the problem. I adapted this slightly for my own purposes - in fact I think you helped me out here man!

Simon &gt; have you got it sorted now?
Replied 28 Jan 2005 16:53:23
28 Jan 2005 16:53:23 Simon Bloodworth replied:
Hi Lee,

Moments before looking at this post i saw that - all seems to be working fine now (fingers crossed).

Once again your help has been invaluable.

Many thanks

Simon

Reply to this topic