Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Query over a form list

Enthusiast ,
Sep 27, 2012 Sep 27, 2012

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

TOPICS
Database access
1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Oct 08, 2012 Oct 08, 2012

Hi Dan

Ahhh. got it.. I was missing list=yes

It works!

Thanks for pointing me in the right direction

Mark

Translate
LEGEND ,
Oct 07, 2012 Oct 07, 2012

In your query, replace the equal sign with the word "in".  Surround your list with parentheses.  Use cfqueryparam with the appropriate attributes.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 07, 2012 Oct 07, 2012

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
query
COUNTRYLONGCOUNTRYSHORTIPFROMIPTO
CACHED false
EXECUTIONTIME 0
SQL SELECT * FROM ipcountry2 where countryshort IN (?)
SQLPARAMETERS
array
1    us,ca   
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 08, 2012 Oct 08, 2012

You are missing an important attribute in your cfqueryparam tag.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 08, 2012 Oct 08, 2012
LATEST

Hi Dan

Ahhh. got it.. I was missing list=yes

It works!

Thanks for pointing me in the right direction

Mark

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources