Hello, I have a query that returns anywhere between 50 and 100 records, depending on the user's options on filtering. When the results are displayed, I would like 9 to display at a time, and having a paging capability to view the next 9, etc. So, the search would show the girst 9 records of the query, with a "next page" link that will show records 10-18, and another "next page" (and "previous page") link that will show the records 19-27, and so on. My problem is, that since the number of records from the query varies, I don't know how to make the paging work. Any help is appreciated. Thanks!
Thanks for the response. I used the provided code, and have it as the following: [B][COLOR="Red"]<!----- Define default values -------->[/COLOR][/B] <cfparam name="form.ART_CATEGORY_ID" default="1"> <cfparam name="form.ART_TYPE_ID" default=""> <cfparam name="form.FINE_ART_CLASS_ID" default=""> <cfparam name="form.searchfield" default=""> Filter by:</p> [B][COLOR="Red"]<!----- Populate filter buttons from database -------->[/COLOR][/B] <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> [B][COLOR="Red"]<!----- Filters to search artwork on -------->[/COLOR][/B] <form method="post" action="root_fineart_frame.cfm"><table width="100%" border="0" cellpadding="4"> <tr valign="top"> <td width="15%"><table width="100%" border="0" cellpadding="2"> <tr> <td colspan="2"><span class="style1 style2">Search artwork: </span></td> </tr> <tr> <td class="style1 style2 style10" > <span class="style3">--</span>Type: </td> <td class="style5" ><span class="style1 style2 style10"> <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> </span></td> </tr> <tr> <td><span class="style1 style2 style10"><span class="style3">--</span>Category: </span></td> <td><span class="style1 style2 style10"> <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> </span></td> </tr> <tr> <td><span class="style1 style2 style10"><span class="style3">--</span>Class:</span></td> <td><span class="style1 style2 style10"> <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> </span></td> </tr> <tr> <td><span class="style1 style2 style10"><span class="style3">-</span> <label>Search: <cfoutput></cfoutput></label> </span></td> <td><span class="style1 style2 style10"> <label><cfoutput> <input name="searchfield" type="text" size="10" value="#form.searchfield#" /> </cfoutput> </label> </span></td> </tr> <tr> <td> </td> <td><span class="style1 style2 style10"> <input name="submit" type="submit" value="Submit" /> </span></td> </tr> [B][COLOR="Red"]<!----- Query for results based on filters -------->[/COLOR][/B] <tr> <cfquery datasource="nancy" name="queryResults"> SELECT r.ART_TITLE, r.DISPLAY, r.IMAGE_THUMB, r.ART_CATEGORY_ID, qi.ART_TYPE_ID, yi.FINE_ART_CLASS_ID FROM ((ART AS r INNER JOIN CATEGORIES AS ri ON r.ART_CATEGORY_ID = ri.ART_CATEGORY_ID ) INNER JOIN TYPE AS qi ON r.ART_TYPE_ID = qi.ART_TYPE_ID) INNER JOIN CLASS AS yi ON r.FINE_ART_CLASS_ID = yi.FINE_ART_CLASS_ID WHERE r.DISPLAY = 1 <cfif val(form.ART_CATEGORY_ID) GT 0> AND r.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 r.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> <td colspan="2"><span class="style10"></span></td> </tr> </table></td> <td width="80%"> </td> </tr> </table></form> [B][COLOR="Red"]<!----- Code from your suggestion -------->[/COLOR][/B] <cfparam name="url.start" default="1"> <cfoutput> <cfset total = #queryResults.RecordCount#> </cfoutput> <cfset perpage = 9> <cfloop index="x" from="#url.start#" to="#min(url.start+perpage-1, total)#"> <cfoutput><span class="style1"> <p><br /> <img src="artwork/#queryResults.IMAGE_THUMB#" /></p> <p>#queryResults.ART_TITLE#</p> </span><br /> </cfoutput> </cfloop> <cfoutput> <cfif url.start gt 1> <a href="#ajaxLink('#cgi.script_name#?start=#url.start-perpage#')#">Previous</a> <cfelse> Previous </cfif> / <cfif (url.start+perpage-1) lt total> <a href="#ajaxLink('#cgi.script_name#?start=#url.start+perpage#')#">Next</a> <cfelse> Next </cfif> </cfoutput> Code (markup): There are two problems I've noticed. 1. Only one record is displayed multiple times over and over. 2. I'd like the results to be listed in a 3x3 table. Any help is appreciated. Thanks!
I too, am having a similar issue, I have the table made already with several data that is being queried on each column. Recently, I have had too add in another column to query and output different data, the problem I am running into is your first problem I believe. The same data is being pulled for each row, when it should be pulling a unique one for each row depending on what the next job ID is for the specific client.