Copy link to clipboard
Copied
Can somebody tell me the correct format for querying the database when I need to pick all records that match from a form entry.
Example if somebody enters US,AU,ZA,SG into a form under the form field name form_country
The way I have it does not work
WHERE countryshort = '#form_country#' |
This gives:
SELECT DISTINCT(countryLong) AS CountryLong,CountryShort FROM ipcountry2 WHERE countryshort = 'US,AU,ZA,SG' ORDER BY countryLong
I need to have it treat the user entry as a list
Thanks
Mark
Hi Dan
Ahhh. got it.. I was missing list=yes
It works!
Thanks for pointing me in the right direction
Mark
Copy link to clipboard
Copied
In your query, replace the equal sign with the word "in". Surround your list with parentheses. Use cfqueryparam with the appropriate attributes.
Copy link to clipboard
Copied
Tried it but it didn't seem to work, no results when I should have seen some records returned. If I enter one country code US for example it finds all the US records, but if I enter two countries, CA,US it does not find both CA and US records, just returns nothing, as below:
Here's the test script
FORM1.CFM
<html><head></head><body>
<form action="form2.cfm" method="post">
<input type="text" name="form_country">
</form></body></html>
FORM2.CFM
<CFQUERY NAME="searchcountry" DATASOURCE="#datasource#">
SELECT countrylong
FROM ipcountry2
where countryshort IN (<cfqueryparam value="#form_country#" cfsqltype="cf_sql_varchar">)
</CFQUERY>
<CFDUMP VAR="#searchcountry#">
RESULT
query | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
RESULTSET |
| ||||||||||
CACHED | false | ||||||||||
EXECUTIONTIME | 0 | ||||||||||
SQL | SELECT * FROM ipcountry2 where countryshort IN (?) | ||||||||||
SQLPARAMETERS |
|
Copy link to clipboard
Copied
You are missing an important attribute in your cfqueryparam tag.
Copy link to clipboard
Copied
Hi Dan
Ahhh. got it.. I was missing list=yes
It works!
Thanks for pointing me in the right direction
Mark