[ic] abit of help on an [if] tag please

Kevin Walsh interchange-users@icdevgroup.org
Sun Jul 21 22:22:02 2002


> 
> I'm trying to do an [if] comparision inside a query but I guess my [if] tags
> are wrong.
> There's not much docs about [if-sql] tags and the ones that I found on the
> interchange lists didn't work either.  Here's my code below.
> 
> <select name="issue_agency" >
> [query sql="SELECT * FROM agency" type=list]
>     <option value="[sql-param code]" 	
> 	[if term="sql-param code" op="eq" compare="/[value issue_agency]/"
> ] selected [/if]>
> 	[sql-param issue_agency]
>     </option>
> [/query]
> </select>
> 
> also found a snippit of code which I changed and didn't work either...
> [set agency_code][value issue_agency][/set] 
> [if type=explicit compare="($Scratch->{agency_code} =~ "/[value
> issue_agency/"] selected 
> [else] problems! [value issue_agency]  [/else]
> [/if]
> 
> I just wanted to print SELECTED on the drop down list.  
>
You could try:

    [if term="[sql-code]" op="eq" compare="[value issue_agency]"]

or (more efficient):

    [if type="value" term="issue_agency" op="eq" compare="[sql-code]"]

or (explicit/compare):

    [tmp agency_code][sql-code][/tmp]
    [if type="explicit" compare=`
        $Values->{issue_agency} eq $Scratch->{agency_code}
    `]

or (depending upon whether you really wanted the regex match):

    [if type="value" term="issue_agency" op="=~" compare="/[sql-code]/"]

or (explicit/compare with regex match):

    [tmp agency_code][sql-code][/tmp]
    [if type="explicit" compare=`
        $Values->{issue_agency} =~ /$Scratch->{agency_code}/
    `]

I imagine that you'll be wanting to use the "equals" rather than the
"regex" method of comparison.

You may find the [selected] tag useful here.  For more information,
see the [selected] and/or [if] entries in the Interchange Tags
Reference.

By the way, the following [loop] code should do exactly what you want
without any additional [if] or [selected] code:

    <select name="issue_agency">
        [loop option="issue_agency" search=|
            st=db
            fi=agency
            ra=yes
            ml=999999
            rf=code,issue_agency
            tf=issue_agency
        |]<option value="[loop-code]">[loop-param issue_agency]</option>
        [/loop]
    </select>

Are you having fun yet?

-- 
   _/   _/  _/_/_/_/  _/    _/  _/_/_/  _/    _/
  _/_/_/   _/_/      _/    _/    _/    _/_/  _/   K e v i n   W a l s h
 _/ _/    _/          _/ _/     _/    _/  _/_/    kevin@cursor.biz
_/   _/  _/_/_/_/      _/    _/_/_/  _/    _/

perl -e 'print qq^9(A)gzqB\r\n\^^^qq^rM7\@\tZ&#ay6\n^'