1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Error executing query... with filters

Discussion in 'Programming' started by lespaul00, Oct 1, 2008.

  1. #1
    Hi. I have a gallery that shows 9 records at a time, which you can then move on to subsequent pages. I added filters to narrow down the record search, however, I am receiving query errors. This is my code:

    
    
    [COLOR="Red"][B]<!----- This is setting the initial defaults for the filter variables ---->[/B][/COLOR]
    <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="">
    
    [COLOR="Red"][B]<!----- Populate the CATEGORIES filter drop-down ---->[/B][/COLOR]
    <cfquery name="categories" datasource="nancy">
    SELECT *
    FROM CATEGORIES
    ORDER BY ART_CATEGORY_ID
    </cfquery>
    
    [COLOR="Red"][B]<!----- Populate the TYPES filter drop-down ---->[/B][/COLOR]
    <cfquery name="types" datasource="nancy">
    SELECT *
    FROM TYPE
    ORDER BY ART_TYPE_ID
    </cfquery>
    
    [COLOR="Red"][B]<!----- Populate the CLASS filter drop-down ---->[/B][/COLOR]
    <cfquery name="class" datasource="nancy">
    SELECT *
    FROM CLASS
    ORDER BY FINE_ART_CLASS_ID
    </cfquery>
    
    
    [COLOR="Red"][B]<!----- Create the filter drop-down selections ---->[/B][/COLOR]
      <form method="post" action="root_fineart.cfm">
    
         <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>
    
         <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>
    
           <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>
    
    [COLOR="Red"][B]<!----- This also creates a SEARCH capability ---->[/B][/COLOR]
    
    <input name="searchfield" type="text" size="10" value="#form.searchfield#" /></cfoutput>      </label>
       
       <input name="submit" type="submit" value="Submit" />
    
    
    [COLOR="Red"][B]<!----- I got this part of the code from a site, that allows me to display the 9 records at a time in my gallery ---->[/B][/COLOR]
    <cfparam name="start" type="numeric" default="1">
              <cfparam name="step" type="numeric" default="9">
              
    [COLOR="Red"][B]<!----- My query to retrieve the records... This may be where I have something wrong... ---->[/B][/COLOR]
    <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 = <cfqueryparam value="#form.ART_CATEGORY_ID#" cfsqltype="cf_sql_integer">
    	</cfif>
    	<cfif val(form.ART_TYPE_ID) GT 0>
    		AND	r.ART_TYPE_ID = <cfqueryparam value="#form.ART_TYPE_ID#" cfsqltype="cf_sql_integer">
    	</cfif>
    			<cfif val(form.FINE_ART_CLASS_ID) GT 0>
    		AND	i.FINE_ART_CLASS_ID = <cfqueryparam value="#form.FINE_ART_CLASS_ID#" cfsqltype="cf_sql_integer">
    	</cfif>
    	<cfif trim(form.searchfield) neq "">
    		AND ART_TITLE LIKE '%#form.searchfield#%'
    	</cfif> 
    	ORDER BY ART_TITLE ASC
            </cfquery>
    
    [COLOR="Red"][B]<!----- This is also code I got somewhere else to display the gallery ---->[/B][/COLOR]
              <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></form>
    
    Code (markup):
    It seems that the CATEGORIES filter is the only one that does not return a ERROR EXECUTING DATABASE QUERY error. However, it does not filter all the records... it only seems to filter and return the first 4 or 5 records.

    Any thoughts?
     
    lespaul00, Oct 1, 2008 IP
  2. lespaul00

    lespaul00 Peon

    Messages:
    283
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Got it... forgot the INNER JOINS
     
    lespaul00, Oct 1, 2008 IP