www.webdeveloper.com
Results 1 to 4 of 4

Thread: Using Variables w/ Include File

  1. #1
    Join Date
    Mar 2008
    Posts
    25

    Using Variables w/ Include File

    I am trying to use dynamic variables in an include file to count the number of times a client is in the db.

    For example: <!--#include file="count_dash_client.asp?client=db_client_name"--> or <!--#include file="count_dash_client.asp?client=jon smith"-->

    I am currently working around this by using an iframe: <iframe src="count_dash_client.asp?client=<%=RS("wr_client_name")%>" ...

    I dont like the workaround and am wondering if anyone has any suggestions for getting the include to work?

    I have seen include virtual used before but not sure what the purpose was.

    Does anyone have any suggestions?

  2. #2
    Join Date
    Jan 2004
    Location
    Melbourne, Australia
    Posts
    5,298
    The includes won't allow you to pass querystring arguments to them as they are not full HTTP requests.

    The contents of the files will be physically merged into the resulting response, therefore any local variables you have in the script will be accessible from the included files.

    For example, if you have a variable called db_client_name, you can access it directly from your included file.

    Cheers,
    Andrew

  3. #3
    Join Date
    Mar 2008
    Posts
    25
    Thanks for the response.

    So theoretically I should be able to have my include file read as follows:
    ----------------------------------------------------
    <&#37;
    Set cn1 = Server.CreateObject("ADODB.Connection")
    cn1.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.Mappath("../xxxxxxx.mdb") & ";"
    SQLQuery = "SELECT wr_client_name FROM table WHERE wr_client_name='" & wr_client_name & "';"
    Set RS1 = cn1.Execute(SQLQuery)

    inv_count = 0
    Do While Not RS1.EOF
    inv_count = inv_count + 1

    RS1.MoveNext
    Loop

    response.write "" & inv_count & ""

    RS1.Close
    Set RS1 = Nothing
    cn1.Close
    Set cn1 = Nothing
    %>
    ----------------------------------------------------

    That should then give me a count of wr_client_name. The page calling the include file reads wr_client_name just fine but the count is coming back with 0.

  4. #4
    Join Date
    Jan 2004
    Location
    Melbourne, Australia
    Posts
    5,298
    Yeah, thats right. The parent page will have access to the local variables of the include.

    You don't really need to iterate through the recordst like that. You should really just be returning the count directly from SQL.
    Code:
    "SELECT COUNT(*) FROM table WHERE wr_client_name='" & wr_client_name & "';"
    Or, you could use the RecordCount property of the RecordSet:
    Code:
    inv_count = RS1.RecordCount
    Cheers.

Thread Information

Users Browsing this Thread

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

Posting Permissions

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



Recent Articles