Two Related Selects Problem

This is a discussion on Two Related Selects Problem within the Cold Fusion forums in Application Servers & Tools category; Hi, I have adopted a version of the two selects related code that ben forta wrote below: However if there is data in the first table that does not have a related record in the second table, I get bind errors. I would also like the second select to show a blank option at the top of each related option. Does anyone know how to do this? Code is shown below... <cfcomponent output="false"> <cfset THIS.dsn="cfartgallery"> <!--- Get array of media types ---> <cffunction name="getMedia" access="remote" returnType="array"> <!--- Define variables ---> <cfset var data=""> <cfset var result=ArrayNew(2)> <cfset var i=0> <!--- ...

Go Back   Application Development Forum > Application Servers & Tools > Cold Fusion

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-23-2008, 10:23 AM
pnugent
Guest
 
Default Two Related Selects Problem

Hi, I have adopted a version of the two selects related code that ben forta
wrote below: However if there is data in the first table that does not have a
related record in the second table, I get bind errors. I would also like the
second select to show a blank option at the top of each related option. Does
anyone know how to do this? Code is shown below...

<cfcomponent output="false">

<cfset THIS.dsn="cfartgallery">

<!--- Get array of media types --->
<cffunction name="getMedia" access="remote" returnType="array">
<!--- Define variables --->
<cfset var data="">
<cfset var result=ArrayNew(2)>
<cfset var i=0>

<!--- Get data --->
<cfquery name="data" datasource="#THIS.dsn#">
SELECT mediaid, mediatype
FROM media
ORDER BY mediatype
</cfquery>

<!--- Convert results to array --->
<cfloop index="i" from="1" to="#data.RecordCount#">
<cfset result[i][1]=data.mediaid[i]>
<cfset result[i][2]=data.mediatype[i]>
</cfloop>

<!--- And return it --->
<cfreturn result>
</cffunction>

<!--- Get art by media type --->
<cffunction name="getArt" access="remote" returnType="array">
<cfargument name="mediaid" type="numeric" required="true">

<!--- Define variables --->
<cfset var data="">
<cfset var result=ArrayNew(2)>
<cfset var i=0>

<!--- Get data --->
<cfquery name="data" datasource="#THIS.dsn#">
SELECT artid, artname
FROM art
WHERE mediaid = #ARGUMENTS.mediaid#
ORDER BY artname
</cfquery>

<!--- Convert results to array --->
<cfloop index="i" from="1" to="#data.RecordCount#">
<cfset result[i][1]=data.artid[i]>
<cfset result[i][2]=data.artname[i]>
</cfloop>

<!--- And return it --->
<cfreturn result>
</cffunction>

</cfcomponent>



<cfform>

<table>
<tr>
<td>Select Media Type:</td>
<td><cfselect name="mediaid"
bind="cfc:art.getMedia()"
bindonload="true" /></td>
</tr>
<tr>
<td>Select Art:</td>
<td><cfselect name="artid"
bind="cfc:art.getArt({mediaid})" /></td>
</tr>
</table>

</cfform>



<cfcomponent output="false">

<cfset THIS.dsn="cfartgallery">

<!--- Get array of media types --->
<cffunction name="getMedia" access="remote" returnType="array">
<!--- Define variables --->
<cfset var data="">
<cfset var result=ArrayNew(2)>
<cfset var i=0>

<!--- Get data --->
<cfquery name="data" datasource="#THIS.dsn#">
SELECT mediaid, mediatype
FROM media
ORDER BY mediatype
</cfquery>

<!--- Convert results to array --->
<cfloop index="i" from="1" to="#data.RecordCount#">
<cfset result[i][1]=data.mediaid[i]>
<cfset result[i][2]=data.mediatype[i]>
</cfloop>

<!--- And return it --->
<cfreturn result>
</cffunction>

<!--- Get art by media type --->
<cffunction name="getArt" access="remote" returnType="array">
<cfargument name="mediaid" type="numeric" required="true">

<!--- Define variables --->
<cfset var data="">
<cfset var result=ArrayNew(2)>
<cfset var i=0>

<!--- Get data --->
<cfquery name="data" datasource="#THIS.dsn#">
SELECT artid, artname
FROM art
WHERE mediaid = #ARGUMENTS.mediaid#
ORDER BY artname
</cfquery>

<!--- Convert results to array --->
<cfloop index="i" from="1" to="#data.RecordCount#">
<cfset result[i][1]=data.artid[i]>
<cfset result[i][2]=data.artname[i]>
</cfloop>

<!--- And return it --->
<cfreturn result>
</cffunction>

</cfcomponent>



<cfform>

<table>
<tr>
<td>Select Media Type:</td>
<td><cfselect name="mediaid"
bind="cfc:art.getMedia()"
bindonload="true" /></td>
</tr>
<tr>
<td>Select Art:</td>
<td><cfselect name="artid"
bind="cfc:art.getArt({mediaid})" /></td>
</tr>
</table>

</cfform>

Reply With Quote
  #2  
Old 08-27-2008, 07:31 PM
Art of Zen
Guest
 
Default Re: Two Related Selects Problem

Does anyone have an answer to this question? Help is urgently needed!

Thanks!
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 06:22 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.