adding an if / cfswitch statement to a query missing peramiters
Hello;
I'm trying to add a feature into a page I made. It has a lot going on, so I'll try and give you the basic function I'm trying to add.. and as little of the other logic as possible.
I want to add a dropdown menu to this page, I have 2 querys running it. one, runs the dropdown.. here is the code for that:
<CFQUERY name="cata" datasource="#APPLICATION.dataSource#" cachedwithin="#CreateTimeSpan(0, 6, 0, 0)#">
select subName, subID
FROM merchSubCat
ORDER BY subName
</CFQUERY>
<form Name="category" method="get" Action="wallProduct.cfm?id=#subID#">
<select name="CategoryID" size="1" class="selectstyle" onChange="category.submit();">
<option value=""> --Select a Category-- </option>
<CFOUTPUT query= "cata">
<option value="#subID#">#subName#</option>
</CFOUTPUT>
</select></form>
ok, simple enough. It takes the info from my db and makes a little menu out of it. click on one of the selections, and it will pass a url.id to the same page. This query is the main query that runs the page. I need it to serve up the first set of records by default, and if you select from the drop down, the according records will be brough up. here is my query to add this feature.
<cfquery name="getMerch" datasource="#APPLICATION.dataSource#">
SELECT merchID, MerchName, MerchDescription, MerchPrice, MYFile, subID, CategoryID
FROM Merchandise
WHERE
<cfif isDefined ("#url.id#")>
<cfswitch expression="#url.id#">
<cfcase value="1">subID = 1</cfcase>
<cfcase value="2">subID = 2</cfcase>
<cfcase value="3">subID = 3</cfcase>
</cfswitch>
<cfelse>
subID = 1
</cfif>
</cfquery>
When my page loads, there is no ID in the url, and my code is not liking this and throwing an erro as such:
Element ID is undefined in URL. | |
| The error occurred in C:\Websites\187914kg3\magWall\wallProduct.cfm: line 19 | |
17 : FROM Merchandise
18 : WHERE
19 : <cfif isDefined ("#url.id#")>
20 : <cfswitch expression="#url.id#">
21 : <cfcase value="1">subID = 1</cfcase>
| |
This is my problem, and I'm sure it's something silly I'm forgetting ehre. I've done this b4. How do I make this work so that by default, subID = 1 is shown when the page loads, and the others are shown when you use the dropdown menu.
I also spoke of other logic on this page. there is a next n button running this query, as well as a cfswitch to switch the order of the records, using the ORDERBY in my query. But I want to get this dropdown menu working before I add in all this other logic.
can anyone help me? I'm having a mental block on this problem.
thank you.
