Paged gallery based on SQL query results

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

  1. #1
    Hello,

    I have the following code. In red is the area of interest. I would like the results to be displayed in 3 columns, rather than just 1:

    <cfparam name="start" type="numeric" default="1">
    <cfparam name="step" type="numeric" default="10">
    <cfquery datasource="mydatabase" cachedwithin=".01" name="queryResults">
    select * 
    from tblrecipes
    order by recipe_name asc
    </cfquery>
    <cfif queryResults.recordcount gt 0>
    <cfoutput>
        <p>
        <!--- 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 + 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-1#">
    
    
    [COLOR="Red"]<table width="100%" border="1" bordercolor="#FFFFFF" cellspacing="0" cellpadding="2">
    <tr>
    	<cfoutput>
    		<td width="33%">#queryResults.RECIPE_NAME#</td>
       		<cfif currentRow mod 3 eq 0>
    	  		</tr>
    		</cfif>	
    	</cfoutput>
    
    </table>[/COLOR]
    
    </cfloop>
    
    Code (markup):
    It displays in one column.... How can I get the results on each page to display in a table with three columns?
     
    lespaul00, Sep 3, 2008 IP
  2. Jamie18

    Jamie18 Peon

    Messages:
    201
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    you're just forgetting to open another row (tr).. swap out the red with this


    <table width="100%" border="1" bordercolor="#FFFFFF" cellspacing="0" cellpadding="2">
    	<tr>
    		<cfoutput>
    			<td width="33%">#queryResults.RECIPE_NAME#</td>
       			<cfif currentRow mod 3 eq 0>
    	  			</tr>
    				<tr>
    			</cfif>	
    		</cfoutput>
    	</tr>
    </table>
    
    Code (markup):
     
    Jamie18, Sep 5, 2008 IP