Dusty
asked on
SQL OR operator question
On my real estate search page form I have a distinct query that pulls in all the property types, "type", and it's quite a few in my dropdown select! I'd like to group some of the property types together to make the select dropdown more user friendly. Such as I'd like to group the type "condo" with "townhouse" and "zero lot line" in my form select dropdown, instead of having :
Condo
Townhouse
Zero Lot Line
I want:
Condo / Townhouse / Zero Lot Line
My form submits to results page query:
<cfif StructKeyExists(form,"Type ") and len(trim(form.Type))>
AND Type = (
<cfqueryparam value="#form.Type#" cfsqltype="cf_sql_varchar" list="true">
)
</cfif>
So on my search form select I tried to hard code the property type like this:
<option value="Townhouse" OR Type="Condominium" OR Type="Zero Lot Line">Condo / Townhouse / Zero Lot Line</option>
It does not throw an error, but it only queries the first type "Townhouse" and not condominium or zero lot line.
Can someone show me a better way to code this?
Thanks!
Condo
Townhouse
Zero Lot Line
I want:
Condo / Townhouse / Zero Lot Line
My form submits to results page query:
<cfif StructKeyExists(form,"Type
AND Type = (
<cfqueryparam value="#form.Type#" cfsqltype="cf_sql_varchar"
)
</cfif>
So on my search form select I tried to hard code the property type like this:
<option value="Townhouse" OR Type="Condominium" OR Type="Zero Lot Line">Condo / Townhouse / Zero Lot Line</option>
It does not throw an error, but it only queries the first type "Townhouse" and not condominium or zero lot line.
Can someone show me a better way to code this?
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
... OR if you have a separate PropertyType table, you could add a "category" column.
Category
1 | Category A
2 | Category B
PropertyType | CategoryID
Condo | 1 <=== Category A
Townhouse | 1 <=== Category A
Zero Lot Line | 1 <=== Category A
Duplex | 2 <=== Category B
Ranch | ......
Then filter on the categoryID value instead. Not tested, but something like:
<select name="categoryID" ...>
<option value="#CategoryID#">Condo / Townhouse / Zero Lot Line</option>
.....
<cfif StructKeyExists(form,"Type ") and listLen(trim(form.Type), "|")>
AND CategoryID = <cfqueryparam value="#form.CategoryID#"
cfsqltype="cf_sql_integer" >
</cfif>
Category
1 | Category A
2 | Category B
PropertyType | CategoryID
Condo | 1 <=== Category A
Townhouse | 1 <=== Category A
Zero Lot Line | 1 <=== Category A
Duplex | 2 <=== Category B
Ranch | ......
Then filter on the categoryID value instead. Not tested, but something like:
<select name="categoryID" ...>
<option value="#CategoryID#">Condo
.....
<cfif StructKeyExists(form,"Type
AND CategoryID = <cfqueryparam value="#form.CategoryID#"
cfsqltype="cf_sql_integer"
</cfif>
ASKER
Quick, concise and perfect! Thank you _agx_
Welcome :) Any time
ASKER