Link to home
Start Free TrialLog in
Avatar of mattboy_slim
mattboy_slim

asked on

How do I query from multiple URL parameters

How can I use Dreamweave MX and multiple URL parameters to query my database?

For example: .........page.asp?month=02&day=26

Here is my current code, where I am only accepting 'month' in the URL parameter:

<%
Dim rs_BlogDate__MMColParam
rs_BlogDate__MMColParam = "1"
If (Request.QueryString("Month") <> "") Then
  rs_BlogDate__MMColParam = Request.QueryString("Month")
End If
%>

<%
Dim rs_BlogDate
Dim rs_BlogDate_numRows

Set rs_BlogDate = Server.CreateObject("ADODB.Recordset")
rs_BlogDate.ActiveConnection = MM_conn_Blog_STRING
rs_BlogDate.Source = "SELECT * FROM Data WHERE Month = " + Replace(rs_BlogDate__MMColParam, "'", "''") + ""
rs_BlogDate.CursorType = 0
rs_BlogDate.CursorLocation = 2
rs_BlogDate.LockType = 1
rs_BlogDate.Open()

rs_BlogDate_numRows = 0
%>

I'd prefer to do this using Dreamweaver, but if I have to do it manually I will. A better grade will go to someone who can help me do this using Dreamweaver Server Behaviors rather than manual coding.

Thanks so much,
Matt Stanzel

Avatar of alexhogan
alexhogan

Matt,

This is actually pretty easy to do.

In DW go to the Application section.

(I'll assume that you already have a database connection)

Select the bindings tab and create a new recordset.

Select the 'Advanced' button.

I'm using the NorthWind database for this example but you'll be able to understand it clearly.

Careate a SQL statement using the tree below by selecting the table fields that you want and then the 'Select' button and then your conditional field and the 'Where' button.

After creating a SQL statement you will have something that looks like this;

SELECT ProductName, CategoryID
FROM Products
WHERE ProductID

You want to add a variable to the 'Where' clause...

SELECT ProductName, CategoryID
FROM Products
WHERE ProductID = iProdID

Now in the variables section of the Advance Query Dialog box you will enter your variable name in the name section;

Name                           Default Value                    Runtime Value
iProdID

You will also want to enter a default value..,

Name                           Default Value                    Runtime Value
iProdID                          1

And finally a runtime value..,

Name                           Default Value                    Runtime Value
iProdID                          1                                   Request.QueryString("ProductID")

The runtime value is where you get the url parameter in this argument.  In ASP 'Request.QueryString()' gets the URL parameters and 'Request.Form()' gets the values from a form that is submitted.  You put the name of the field that you are looking to return data on and the variable that will contain that value.

The above example will get '121' from the following url..,

http://www.mydomain.com/getme.asp?iProdID=121
Avatar of mattboy_slim

ASKER

Alex, sorry, I did not communicate my issue well enough.

Right now, I am querying against the URL parameter "Month", but would like to query against multiple parameters, such as "Month" and "Day". So I have the first part done (what you have explained above), but would like to query an additional URL parameter also.

Thanks again,
Matt
ASKER CERTIFIED SOLUTION
Avatar of alexhogan
alexhogan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the help so far Alex, I'm still having trouble, though your solution did fix me up. I'll show screenshots and URLs with their results
====================================================================

Single URL Parameter, works fine:
http://www.mattstanzel.com/images/ee_rs-01.gif
URL gives me two results from the day "26", works correctly
http://www.mattstanzel.com/page.asp?day=26

=======================================

When I add the dual Request.Querystrings, Single URL parameters do not work anymore:
http://www.mattstanzel.com/images/ee_rs-02.gif
URLs give me no results:
http://www.mattstanzel.com/page.asp?day=26
http://www.mattstanzel.com/page.asp?month=02

=======================================

Is this how it is supposed to work? When I add the ability to query using multiple URL parameters, does it disable my ability to use only a single URL parameter, or do I have to use "IF" statements to determine whether there is a single or double URL parameters?

Thanks so much,
Matt

Your URL should be;

http://www.mattstanzel.com/page.asp?month=02&day=26

That will give you the results you want.
You will have to use some kind of branching statement to distinguish between single and multiple url params.