469,322 Members | 1,605 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,322 developers. It's quick & easy.

Define a recordset within a function

I've got 20 pages that all have an identical code block that opens a db and assigns recordset to variables. Only difference is the product_id used in the query. I want to move this code to an include, and just call it on each page.
If I put the function on the actual page it works, but once I put it in the include I'm getting the error: Variable is undefined: 'prod_query'
I've tried doing it as both a sub and a function, but get the same error.
the include that defines the prod_query function is called before I try to use it. Any clues what I'm doing wrong? I'm not trying to return a value from the function, just using it to define variables I use later on the page.

<%@ Language=VBScript %>
<% OPTION EXPLICIT %>
<!--#include file="shop$db.asp"-->
<!--#include file="INC_prod_query.asp"-->
<%
Dim product_id
product_id = 69
Dim dbc, rs
shopopendatabaseP dbc
prod_query(product_id) ' call function in INC_prod_query.asp
%>

Here is the include file:
dim query, prod_name, prod_description, prod_extendeddesc, prod_ingredients, prod_price, prod_image, prod_weight
function prod_query(id)
query = "select cname, cdescription, extendeddesc, ingredients, pother1, cprice, cimageurl from products where catalogid = " & product_id
set rs = dbc.execute(query)
If not rs.EOF Then
prod_name = rs("cname")
prod_description = rs("cdescription")
prod_extendeddesc = rs("extendeddesc")
prod_ingredients = rs("ingredients")
prod_price = rs("cprice")
prod_image = rs("cimageurl")
prod_weight = rs("pother1")
end if
set rs=nothing
exit sub
end function
Mar 6 '07 #1
1 1862
iam_clint
1,208 Expert 1GB
query = "select cname, cdescription, extendeddesc, ingredients, pother1, cprice, cimageurl from products where catalogid = " & product_id

should be
query = "select cname, cdescription, extendeddesc, ingredients, pother1, cprice, cimageurl from products where catalogid = " & id

since your passing the variable to it.
Mar 6 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Gerry Abbott | last post: by
8 posts views Thread by LabGeek | last post: by
2 posts views Thread by fpennisi | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Gurmeet2796 | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.