• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 571
  • Last Modified:

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

0
mattboy_slim
Asked:
mattboy_slim
  • 4
  • 2
1 Solution
 
alexhoganCommented:
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
0
 
mattboy_slimAuthor Commented:
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
0
 
alexhoganCommented:
OK..,

So you just add another variable to the variables list and another condistion to the 'Where' clause.

SELECT ProductName, CategoryID
FROM Products
WHERE ProductID = iProdID
AND CatagoryID = iCatID

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

http://www.mydomain.com/getme.asp?iProdID=121&iCatID=7
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
mattboy_slimAuthor Commented:
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

0
 
alexhoganCommented:
Your URL should be;

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

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

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now