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

Check to see if variable is in recordset

Explorer ,
Jun 17, 2009 Jun 17, 2009

I have a queryparam recordset in my page (let's call it rs_authorized), and I have a form-submitted value (let's call it form.county).  I want to do a <cfif> statement based on whether or not the variable is in the recordset.

I have tried...

<cfif #form.county# EQ <rs_authorized.county_name#>

but it only recognizes if it's the first value of the recordset.

I tried...

<cfif ListFind(#rs_authorized.county_name#,#form.county#)>

but again, it only recognizes if it's the first value of the recordset.

I tried...

<cfif #form.county# IN (#rs_authorized.county_name#)>

but I get an error saying it doesn't recognize the word 'IN'.

Any ideas?

TOPICS
Advanced techniques
605
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

Valorous Hero , Jun 17, 2009 Jun 17, 2009

Depending on what exactly you are trying to do here you probably need to do one or more of the following:

1) Use a fully qualified record set reference of queryName.column.row:

I.E.

#rs_quthorized.county_name[2]#

2) Loop over the recordset to search all the rows.  <cfoutput query="..."> or <cfloop query="..."> constructs make this rather easy to do, but nothing is preventing you from using any looping mechinism you care to use.

3)Use the valueList(queryName.column) function to turn all the date from

...
Translate
Valorous Hero ,
Jun 17, 2009 Jun 17, 2009

Depending on what exactly you are trying to do here you probably need to do one or more of the following:

1) Use a fully qualified record set reference of queryName.column.row:

I.E.

#rs_quthorized.county_name[2]#

2) Loop over the recordset to search all the rows.  <cfoutput query="..."> or <cfloop query="..."> constructs make this rather easy to do, but nothing is preventing you from using any looping mechinism you care to use.

3)Use the valueList(queryName.column) function to turn all the date from one column in the record set into a list.  This combined with either a listFind() or listContains() function will allow you to quickly search for a single value.

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
Explorer ,
Jun 17, 2009 Jun 17, 2009
LATEST

...and number 3 is the winner!

Thanks, I was not familiar with the valueList() function, but it worked perfectly.  You ROCK.

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