0

What i am trying todo in coldfusion cfscript is iterate through a request collection of variables and do some evaluation, which i can do easily in PHP, but am running into issue translating to coldfusion cfscript, because it seems i cannot build a dynamic if statement

PHP

for ( $i=0 ; $i<count($aColumns) ; $i++ )
    {
        if ( $_GET['bSearchable_'.$i] == "true" && $_GET['sSearch_'.$i] != '' )
        {
            //If there was no where clause
            if ( $sWhere == "" )
            {
                $sWhere = "WHERE ";
            }
            else
            {
                $sWhere .= " AND ";
            }

I have tried this, errored out

for (i=1; i<= iColumnsLen; i++) {   
  if (rc.bSearchable_&i EQ true and rc.sSearch&i NEQ '') {
            if ( sWhere EQ "" )
            { sWhere = " WHERE "; }
            else
            { sWhere &= " AND ";}
  }         
}

also tried changing the if statement line to this, same

if (rc.bSearchable_+i EQ true and rc.sSearch+i NEQ '') {

finally i attempted building a string and using that , i knew it wouldnt work but i thought i'd give it a shot, error was could not convert var to boolean

for (i=1; i<= iColumnsLen; i++) {
 var iterator = "rc.bSearchable_"&i&" EQ true and rc.sSearch_"&i&" NEQ ''";
  if (#iterator#) {

Here's the static coldfusion without iteration that i am desiring to be done problematically

  if (rc.bSearchable_1 EQ true and rc.sSearch_1 NEQ '') {
            if ( sWhere EQ "" )
            { sWhere = " WHERE "; }
            else
            { sWhere &= " AND ";}
  }         
  if (rc.bSearchable_2 EQ true and rc.sSearch_2 NEQ '') {
            if ( sWhere EQ "" )
            { sWhere = " WHERE "; }
            else
            { sWhere &= " AND ";}
  } 
  if (rc.bSearchable_3 EQ true and rc.sSearch_3 NEQ '') {
            if ( sWhere EQ "" )
            { sWhere = " WHERE "; }
            else
            { sWhere &= " AND ";}                                     
  }

any help would be much obliged

Jay Rizzi
  • 4,196
  • 5
  • 42
  • 71
  • 3
    *I have tried this, errored out*. What is the error message? FYI: The `URL` scope is a structure. You can access the values dynamically using associative array notation: ie `url["someFixedName"& counterVariable ]`. – Leigh Jun 04 '13 at 14:49
  • .. the same applies to any structure. – Leigh Jun 04 '13 at 15:03

1 Answers1

3

As Leigh says, you just need to refer to dynamic columns like this:

rc["bSearchable_" & i] 
rc["sSearch_" & i]
duncan
  • 31,401
  • 13
  • 78
  • 99