Hi guys im having trouble with this setup.

Let me explain - I have three cfselect fields and each one of them is related 
so we have category / sub-category / products.

I keep getting and "Internal Server Error" when i initially browse to the page. 
yet the cfselects all work correctly producing the correct information and if i 
was to change the category or the sub category then again they all work without 
any error messages, it just happens when i go to the page for the first time so 
i think the problem might be when the cfc loads.

Attached below is the CFC and also the cfm page with trimmed down.

Thanks

CFC
<cfcomponent output="false">

    <cfset THIS.dsn="#application.dsn#">

    <!--- Get array of media types --->
    <cffunction name="getCategory" 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 ID as categoryid, PROD_CATEGORY as category
        FROM PRODUCT_CATEGORY
        ORDER BY category
        </cfquery>

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

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

    <!--- Get art by media type --->
    <cffunction name="getsubcategory" access="remote" returnType="array">
        <cfargument name="categoryid" 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     dbo.PROD_SUB_CATEGORY.SUB_CATEGORY as product, 
dbo.PROD_SUB_CATEGORY.ID as productid
FROM         dbo.PRODUCT_CATEGORY INNER JOIN
                      dbo.PROD_SUB_CATEGORY ON dbo.PRODUCT_CATEGORY.ID = 
dbo.PROD_SUB_CATEGORY.REL_PRODUCT_CATEGORY
WHERE     (dbo.PROD_SUB_CATEGORY.REL_PRODUCT_CATEGORY = #ARGUMENTS.categoryid#)
        </cfquery>
    
     <cfloop index="i" from="1" to="#data.RecordCount#">
            <cfset result[i][1]=data.productid[i]>
            <cfset result[i][2]=data.product[i]>
        </cfloop>

        <!--- And return it --->
        <cfreturn result>
    </cffunction>
    
     <!--- Get art by media type --->
    <cffunction name="getproducts" access="remote" returnType="array">
        <cfargument name="categoryid" type="numeric" required="true">
        <cfargument name="subcategoryid" 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 ID as productid, DESCRIPTION as product
        FROM PRODUCTS
        WHERE REL_PROD_CATEGORY = #ARGUMENTS.categoryid# AND 
(REL_PROD_SUB_CATEGORY = #ARGUMENTS.subcategoryid#)
        ORDER BY product
        </cfquery>
    
    
        <!--- Convert results to array --->
        <cfloop index="i" from="1" to="#data.RecordCount#">
            <cfset result[i][1]=data.productid[i]>
            <cfset result[i][2]=data.product[i]>
        </cfloop>

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

</cfcomponent>




CFM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
<html xmlns="http://www.w3.org/1999/xhtml";>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body><cfform name="form1" id="form1">
<table width="678" height="125" border="0" align="center" cellpadding="0" 
cellspacing="0" class="normal_text">
  <tr>
    <td width="86">&nbsp;</td>
    <td width="218" class="field_label">&nbsp;</td>
    <td width="25">&nbsp;</td>
    <td width="349">&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td class="field_label">Product Category</td>
    <td>&nbsp;</td>
    <td><cfselect bind="cfc:products.getcategory()" bindonload="true" 
name="categoryid" class="field_medium" id="categoryid" /></td>
  </tr>
  <tr>
    <td height="28">&nbsp;</td>
    <td class="field_label">Product Sub Category</td>
    <td>&nbsp;</td>
    <td><cfselect bind="cfc:products.getsubcategory({categoryid})" 
name="subcategoryid" class="field_medium" id="subcategoryid" /></td>
  </tr>
  <tr>
    <td height="28">&nbsp;</td>
    <td class="field_label">Product</td>
    <td>&nbsp;</td>
    <td><cfselect bind="cfc:products.getproducts({categoryid},{subcategoryid})" 
name="search1" class="field_xlarge" id="search1" /></td>
  </tr>
  <tr>
    <td height="38">&nbsp;</td>
    <td class="field_label"><em>Tip:</em> Enter search criteria and click show 
records, clicking show records.</td>
    <td>&nbsp;</td>
    <td><input type="button" name="button2" style="width:100px" class="style4" 
id="button2" onclick="BtnSearch()" value="Show Records" /></td>
  </tr>
</table>
</cfform>
</body>
</html>


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:340463
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm

Reply via email to