Using CFQUERY and CFSELECT to pull multiple values based on selection

a 夏天 提交于 2020-01-17 13:49:06

问题


I have a CFQUERY pulling three columns. The following CFSELECT allows the user to make a selection from various results based on the 'display' parameter, and sets the value to the 'value' parameter.

I would like to pass the third unused value of that record to a variable to be used in a later query. I cannot set the 'value' field to the column I need since that value is needed in a query following this one (queries populate based on previous drop down selections).

Is there a way to do this? To somehow have the CFSELECT grab 2 separate values?

SubRegionName is Displayed.

State is the value to pass.

SubRegionCD for this selection made is needed later.

Code example below:

    <cfquery name="qrySubTurf"
 DATASOURCESTUFF>
 SELECT SubRegionName, SubRegionCd, State
 From dbo.tblRegions 
 where Region='#form.getRegion#'  <!---Previous CFSELCT value--->
 order by SubRegionName
     </cfquery>

     <cfselect name="getSubTurf"
 style="width:220px"
 size=1
 multiple="no"
 query="qrySubTurf"
 value="state"                   <!---Value passed to the next CFQUERY--->
 display="SubRegionName"         <!---Value displayed to user--->
 queryPosition="below"
 onChange="AddForm.submit();">
        <option value=""></option>
     </cfselect>

Now I need to grab the SubRegionCD associated with the users selection of State and SubRegionName and assign it to a variable that can be used in the final query. I cannot use State alone to determine the SubRegionCD, but I CAN use SubRegionName to make a 1-1 match. Help?


回答1:


Simplest (in terms of littlest-possible code change) would be to do:

<cfquery name="qrySubTurf"
 DATASOURCESTUFF>
 SELECT SubRegionName, SubRegionCd + ',' + State AS Key
 From dbo.tblRegions 
 where Region=<cfqueryparam value="#form.getRegion#" cfsqltype="CF_SQL_VARCHAR">
 order by SubRegionName
</cfquery>

<cfselect name="getSubTurf"
 style="width:220px"
 size=1
 multiple="no"
 query="qrySubTurf"
 value="Key"
 display="SubRegionName"
 queryPosition="below"
 onChange="AddForm.submit();">
  <option value=""></option>
</cfselect>

And then use ListFirst(FORM.getSubTurf) and ListLast(FORM.getSubTurf). Also, don't forget to use <cfqueryparam>.




回答2:


To maintain the query result across pages you have to split the value returned to the form's action page ... this is was the answer suggested ... <cfqueryparam value ="#ListFirst(form.***)#>



来源:https://stackoverflow.com/questions/4753545/using-cfquery-and-cfselect-to-pull-multiple-values-based-on-selection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!