Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query information into two columns per page. 1

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I have built a query that allows only 4 queried items to show per page. If there are more then 4 queries, a "next page" button appears. Question is, How can I make those 4 queries per page go into 2 columns containing 2 items each...like this.

Page1
img1 img2
img3 img4


Page2
img5 img6
img7 img8

and so on
 
it's not a coldfusion problem but an html one
<table><tr><td>img1</td><td>img2</td></tr>
<tr><td>img3</td><td>img4</td></tr></table>
 
Active Server Pages can do this with a horizontal looper. Here is the code I found to accomplish it. Translating the VBScript into ColdFusion shouldn't be difficult. It's a Macromedia Dreamweaver extension, so I'm not exactly sure how to extrapolate it, but I'm sure someone does.


Code:
<!-- declare variables -->
<%
dim numberColumns
dim startrw
dim endrw
dim numrows
%>

<%
startrw = 0
endrw = Repeat1__index
numberColumns = 2
numrows = -1
while((numrows <> 0) AND (Not rsCatalogueItems.EOF))
	startrw = endrw + 1
	endrw = endrw + numberColumns
%>

<!-- First column -->
<%
While ((startrw <= endrw) AND (Not rsCatalogueItems.EOF))
%>

<!-- Actual database items -->
<table>
<tr>
<td>
<%=(rsCatalogueItems.Fields.Item(&quot;ItemPrice&quot;).Value)%>
</td>
</tr>
</table>

<!-- Start the next column -->
<%
startrw = startrw + 1
rsCatalogueItems.MoveNext()
Wend
%>
	
<%
numrows=numrows-1
Wend
%>


I hope you, or someone who knows better than I, can take this to the next level and help with your ColdFusion coding problem.

Good luck,

JR
 
<table><tr>
<cfoutput query=&quot;...&quot; startrow=#start# maxrows=2>
<td>yourquery.yourcol</td>
</cfoutput>
</tr>
<tr>
<cfoutput query=&quot;...&quot; startrow=#start#+2 maxrows=2>
<td>yourquery.yourcol</td>
</cfoutput>
</tr></table>

the first time you call the page set start=0 then &quot;next&quot; calls the page with start=start+4 and &quot;previous&quot; with start=start-4
 
Attached code is even easier I think. Instead of the the 2 in the <cfif> construction you can use any number. Practically you define the number of table columns there. Check it out and let me know what you think of it.

<table>
<tr>
<cfoutput query=&quot;MyQuery&quot;>
<td>#img#</td>
<cfif MyQuery.CurrentRow MOD 2 IS 0>
</tr>
<tr>
</cfif>
</cfoutput>
</tr>
</table>

Regards,

<webguru>iqof188</webguru>
 
iza, (or anybody),

how do you set start=1 on the page? i mean, how do you define start to be 1 on the first page? And how do you define start to be 5 on the second page? How does the second page know where to start from?

thanks!

-ian
Ian Hall
Multimedia Designer
 
Iza, you are right, I didn't properly read the question. In the <cfoutput query> tag you should define startrow like you did, since you have to split the results returned over several pages. Still, my snippet of code can create a tow-column table with the results. Combine it woth your code, and the solution is there!

Regards,

<webguru>iqof188</webguru>
 
iqof188 : i love your elegant way to display tables :)
brown : there are many ways to do this, the best i can think of is by passing parameters : something either like the_page.cfm?start=0 or like <input type=hidden name=start value=0> - and then increment/decrement the value of startrow when changing pages
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top