Dynamic checkboxes - multiple where statements for checkboxes selected

Discussion in 'Programming' started by lespaul00, Sep 6, 2008.

  1. #1
    Hello,

    I have a form with a few different types of artwork to display. I have each type with a checkbox, that I want the artwork to be filtered on upon one (or multiple) types being selected. Here's my code so far:

    <cfparam name="form.ART_TYPE_ID" default="0">
    
    <cfquery name="getTypes" datasource="nancy">
    SELECT ART_TYPE_ID, ART_TYPE
    FROM   TYPE
    ORDER BY ART_TYPE
    </cfquery>
    
    <form method="post" action="Untitled-3.cfm">
    <table width="100%" cellspacing="0" cellpadding="0" border="0">
    
       <tr>
            <cfoutput>
            <td valign="top">
              
                
                Type
    			<div id=" TypeDiv" style="padding-left:1px; display:show" > 
    			  <cfloop query="getTypes">
    			    <input type="checkbox" name="#ART_TYPE_ID#" value="#ART_TYPE_ID#" size="50">#ART_TYPE#<br />
    	</cfloop>
    	</div>
    </td>
    
    </cfoutput>
    </tr>
    </table>
       <input name="submit" type="submit" value="Search" />
    </form>
    
    
    <p>
      <cfquery name="getArt" datasource="nancy">
      SELECT *
      FROM ART
      WHERE ART_TYPE_ID = #form.ART_TYPE_ID#
      ORDER BY ART_TITLE
    </cfquery>
    </p>
    
    <cfoutput query="getArt">
    #ART_TITLE#
    </cfoutput>
    
    
    Code (markup):
    First of all, i'm getting errors. Second of all, I don't know how to integrate multiple checkboxes selected into the SQL WHERE statement. Thoughts?
     
    lespaul00, Sep 6, 2008 IP
  2. CR250

    CR250 Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2

    What errors are you getting? If the SQL is right then that should produce the checkboxes.
     
    CR250, Sep 7, 2008 IP
  3. lespaul00

    lespaul00 Peon

    Messages:
    283
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I'm getting the following error:

    This is my current code (relevant pieces):

    
    <cfparam name="form.ART_CATEGORY_ID" default="">
    <cfparam name="form.ART_TYPE_ID" default="">
    <cfparam name="form.FINE_ART_CLASS_ID" default="">
    <cfparam name="form.searchfield" default="">
    
    Filter by:</p>
    <form method="post" action="root_fineart.cfm">
    
    
    <cfquery name="categories" datasource="nancy">
    SELECT *
    FROM CATEGORIES
    ORDER BY ART_CATEGORY_ID
    </cfquery>
    
    <cfquery name="types" datasource="nancy">
    SELECT *
    FROM TYPE
    ORDER BY ART_TYPE_ID
    </cfquery>
    
    
    <cfquery name="class" datasource="nancy">
    SELECT *
    FROM CLASS
    ORDER BY FINE_ART_CLASS_ID
    </cfquery>
    
    type:
     <select name="ART_TYPE_ID">
       <option value="" <cfif trim(form.ART_TYPE_ID) eq "">selected
    				</cfif>> All </option>
    							
       <cfoutput query="types">
    	 <option value="#ART_TYPE_ID#" 
              <cfif form.ART_TYPE_ID eq types.ART_TYPE_ID>selected</cfif>>#ART_TYPE#</option>
       </cfoutput>
      </select>
    		
    
    CATEGORY: 
     <select name="ART_CATEGORY_ID">
       <option value="" <cfif trim(form.ART_CATEGORY_ID) eq "">selected
    				</cfif>> All </option>
    							
       <cfoutput query="categories">
    	 <option value="#ART_CATEGORY_ID#" 
              <cfif form.ART_CATEGORY_ID eq categories.ART_CATEGORY_ID>selected</cfif>>#ART_CATEGORY#</option>
       </cfoutput>
      </select> 
    
    Class: 
     <select name="FINE_ART_CLASS_ID">
       <option value="" <cfif trim(form.FINE_ART_CLASS_ID) eq "">selected
    				</cfif>> All </option>
    							
       <cfoutput query="class">
    	 <option value="#FINE_ART_CLASS_ID#" 
              <cfif form.FINE_ART_CLASS_ID eq class.FINE_ART_CLASS_ID>selected</cfif>>#FINE_ART_CLASS#</option>
       </cfoutput>
      </select> 
    
     <label>Search:
     <cfoutput>
    <input name="searchfield" type="text" size="10" value="#form.searchfield#" /></cfoutput>      </label>
       
       <input name="submit" type="submit" value="Submit" />
    
    </form>
    
    <cfparam name="start" type="numeric" default="1">
              <cfparam name="step" type="numeric" default="9">
              <cfquery datasource="nancy" cachedwithin=".01" name="queryResults">
    SELECT *
    FROM ART
    	WHERE  1 = 1
    	<cfif val(form.ART_CATEGORY_ID) GT 0>
    		AND	 ART_CATEGORY_ID = [COLOR="Red"]<cfqueryparam value="#form.ART_CATEGORY_ID#" cfsqltype="cf_sql_integer">[/COLOR]
    	</cfif>
    	<cfif val(form.ART_TYPE_ID) GT 0>
    		AND	r.ART_TYPE_ID = [COLOR="red"]<cfqueryparam value="#form.ART_TYPE_ID#" cfsqltype="cf_sql_integer">[/COLOR]
    	</cfif>
    			<cfif val(form.FINE_ART_CLASS_ID) GT 0>
    		AND	i.FINE_ART_CLASS_ID = [COLOR="red"]<cfqueryparam value="#form.FINE_ART_CLASS_ID#" cfsqltype="cf_sql_integer">[/COLOR]	</cfif>
    	<cfif trim(form.searchfield) neq "">
    		AND ART_TITLE LIKE '%#form.searchfield#%'
    	</cfif> 
    	ORDER BY ART_TITLE ASC
            </cfquery>
              <cfif queryResults.recordcount gt 0>
                <cfoutput>
                  <p class="style1">
                    <!--- if past start --->
                    <cfif (start-step-step) gt 1>
                      <a href="#cgi.SCRIPT_NAME#?start=1"><img src="images/Beginning_blue.png" alt="Beginning" width="31" height="21" align="absbottom" /></a>
                    </cfif>
                    <cfif start gt 1>
                      <a href="#cgi.SCRIPT_NAME#?start=#start-step#"><img src="images/previous_blue.png" alt="Previous" align="absbottom" /></a>
                    </cfif>
                    <strong>#start# - #iif(start * 3 + step gt queryResults.recordcount,queryResults.recordcount,start + step-1)# of #queryResults.recordcount# records</strong>
                    <!--- if still some not displayed --->
                    <cfif (start + step) lte queryResults.recordcount>
                      <a href="#cgi.SCRIPT_NAME#?start=#start+step#"><img src="images/next_blue.png" alt="Next" align="absbottom" /></a>
                    </cfif>
                    <cfif (start+step+step) lte queryResults.recordcount>
                      <a href="#cgi.SCRIPT_NAME#?start=#queryResults.recordcount-step+1#"><img src="images/end_blue.png" alt="End" align="absbottom" /></a>
                    </cfif>
                  </p>
                </cfoutput>
              </cfif>
              <cfloop query="queryResults" startrow="#start#" endrow="#start + step/3-1#">
                <table width="100%" border="1" bordercolor="#FFFFFF" cellspacing="0" cellpadding="2">
                  <tr> <cfoutput query="queryResults" startrow="#start#" maxrows="3">
                      <td width="33%" class="style1">#queryResults.ART_TITLE#</td>
                  </cfoutput>
                      <cfset #start# = #start# + 3>
                  </tr>
                </table>
              </cfloop>
          </td>
        </tr>
      </table>
    
    Code (markup):
    I am assuming my problem is in red above. Any work-around, with minor changes to the code? The parameters above in red will always be numbers (if that helps).

    Thanks.
     
    lespaul00, Sep 8, 2008 IP