Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

cfselect bind to another cfselect

Posted on 2012-12-20
6
Medium Priority
?
406 Views
Last Modified: 2012-12-27
Hi all, need help with a cfselect bind.

I'm using this as a tutorial: http://tutorial544.easycfm.com/

Here's my page:  http://pcgrecords.com/vol/test.cfm

The first select, year, isn't bound, so ignore that.  But the rest of the cfselects on that page have a bind to the one before it.  (So the 'makes' one populates the 'models', and etc.)

Everything is ok until I get to the last one.  What I really want, is for the last cfselect, Select an OE, to be bound not just to the engine cfselect before it, but to the select model field as well.

Please help!

Here's the relevant code on the page, and the cfc is attached in a txt file.

   <tr>
         <td>Select Model:</td>
         <td><cfselect name="model" bindOnLoad="Yes" bind="cfc:data.getmodel({makes})" />
         </td>
</tr>
 <tr>
         <td>Select Engine:</td>
         <td><cfselect name="engine" bindOnLoad="Yes" bind="cfc:data.getengine({model})" />
         </td>
</tr>
<tr>
         <td>Select OE:</td>
         <td><cfselect name="OE"  bind="cfc:data.getOE({engine})" />
         </td>
</tr>

---------
0
Comment
Question by:Rush_2112
  • 3
  • 3
6 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 2000 total points
ID: 38711378
Did you forget to attach the cfc/txt file? I don't see it.

Quick aside, the "Engine" list seems to repeat the same value multiple times. Not sure if that's what you want?

      > What I really want, is for the last cfselect, Select an OE, to be
      > bound not just to the engine cfselect before it, but to the select
      > model field as well.

You can bind to multiple fields.  Just add the second field to your bind

    <cfselect name="OE"  bind="cfc:data.getOE({model}, {engine})" />

... and as another argument to your cffunction/query.  (I can't be more specific without


      <cffunction name="getOE" ....>
               <cfargument name="model" ....>
               <cfargument name="engine" ....>
                ...

                <cfquery>
                     SELECT  SomeColumns
                     FROM    YourTable
                     WHERE   ModelColumn = <cfqueryparam value="#argument.model#" ...>
                     AND       EngineColumn = <cfqueryparam value="#argument.engine#" ...>
                </cfquery>

                ....
      </cffunction>
0
 
LVL 1

Author Comment

by:Rush_2112
ID: 38713520
Sorry, guess it didn't upload... its there now.   Thanks for helping.  

I was following a tutorial so I don't know what that line does or why it's duplicated.  Does the cfc help?
cfc.txt
0
 
LVL 1

Author Closing Comment

by:Rush_2112
ID: 38713851
Thanks, even without the rest of the code, you got it!
0
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
LVL 52

Expert Comment

by:_agx_
ID: 38713989
Looks like it's just duplicated in the data ie db table. So just add a DISTINCT in the query. That'll take care of it.

Btw, the tutorial code is a little outdated.  As of CF8.0.1 you can bind directly to a query, so there's no need to build a separate array.  Just return the query from the function.  Then specify the "value" and "display" column in your cfselect.  

It's also a good practice to 1) always VAR scope variables (prevent hard to trace threading problems) and 2) use cfqueryparam (sql injection) and 3) scope all variables

Here's how I'd rewrite it.  Unfortunately I can't test it out right now, watch out for typos.

FORM

<tr>
         <td>Select Model:</td>
         <td><cfselect name="model" bindOnLoad="Yes" bind="cfc:data.getmodel({makes})"
                 display="model" value="model" />
         </td>
</tr>
 <tr>
         <td>Select Engine:</td>
         <td><cfselect name="engine" bindOnLoad="Yes" bind="cfc:data.getengine({model})"
                 display="engine" value="engine" />
         </td>
</tr>
<tr>
         <td>Select OE:</td>
         <td><cfselect name="OE"  bind="cfc:data.getOE({model}, {engine})" 
                 display="OE" value="OE" />
         </td>
</tr>

Open in new window


CFC
<cfcomponent output="false">
    <cfset variables.dsn = "Volusion">

    <cffunction name="getmakes" access="remote" returntype="query">
        <cfset var getData = "">

        <cfquery name="getData" datasource="#variables.dsn#"> 
            SELECT DISTINCT make FROM ECM
            ORDER BY make
        </cfquery>

        <cfreturn getData />
    </cffunction>
    
    <cffunction name="getmodel" access="remote" returntype="query">
        <cfargument name="make" type="string" required="true">
    
        <cfset var getData = "">
        <cfquery name="getData" datasource="#variables.dsn#">
            SELECT DISTINCT model FROM ECM
            WHERE make = <cfqueryparam value="#arguments.make#" cfsqltype="cf_sql_varchar">
            ORDER BY model
        </cfquery>

        <cfreturn getData />
    </cffunction>
    
    <cffunction name="getengine" access="remote" returntype="query">
        <cfargument name="model" type="string" required="true">
    
        <cfset var getData = "">
        <cfquery name="getData" datasource="#variables.dsn#">
            SELECT  engine FROM ECM
            WHERE model = <cfqueryparam value="#arguments.model#" cfsqltype="cf_sql_varchar">
            ORDER BY model
        </cfquery>

        <cfreturn getData />
    </cffunction>
    
    <cffunction name="getOE" access="remote" returntype="query">
        <cfargument name="model" type="string" required="true">
        <cfargument name="engine" type="string" required="true">
    
        <cfset var getData = "">
        <cfquery name="getData" datasource="#variables.dsn#">
            SELECT OE FROM ECM
            WHERE model = <cfqueryparam value="#arguments.model#" cfsqltype="cf_sql_varchar">
            AND   engine = <cfqueryparam value="#arguments.engine#" cfsqltype="cf_sql_varchar">
            ORDER BY OE
        </cfquery>

        <cfreturn getData />
    </cffunction>
    
</cfcomponent>

Open in new window

0
 
LVL 52

Expert Comment

by:_agx_
ID: 38720851
> Thanks, even without the rest of the code, you got it!

Oops.. sorry I missed your last comment before posting :) (But having a fuller example for the archives couldn't hurt) Anyway, glad I could help.
0
 
LVL 1

Author Comment

by:Rush_2112
ID: 38723886
thanks for the update!  I'll try that out too!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question