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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple Records per Row 1

Status
Not open for further replies.

ybn1197

Technical User
May 20, 2002
12
US
I'm fairly new to ASP/Database and I'm having difficulty with a output format. I have a page that displays 2 fields of a recordset in a table. There are multiple recordsets in the table. What I have displaying when the page runs is a long, skinny table. What I would like is a shorter and wider table that would display multiple recordsets (preferably three) in the same row before moving to the next row. I've tried some things from 4guysfromrolla.com but I keep getting syntax errors on the output.
Here is the table and the repeat region as I have it. I work in Dreamweaver and use a Access database, which is, IMO, where I'm having problems with the above mentioned tutorials.
Code:
<% 
While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF)) 
%>
<table border=&quot;1&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;>
 <tr> 
  <td width=&quot;50&quot;><%=(Recordset1.Fields.Item(&quot;LocationID&quot;).Value)%></td>
  <td><%=(Recordset1.Fields.Item(&quot;LocationTitle&quot;).Value)%></td>
 </tr>
</table>
<% 
  Repeat1__index=Repeat1__index+1
  Repeat1__numRows=Repeat1__numRows-1
  Recordset1.MoveNext()
Wend
%>
Is there anyone that can help me turn this into a multiple columns/same row format. I'd hate to have one long skinny table with about 140 recordsets.
 
All right, here you go. I just got done with this. It was actually pretty fun to figure out. You can copy and paste this into a sample ASP page to see how it works out. I specify different shades of gray based on each grouping, which is the number of columns you want for each recordset, which is 3.Well, just test it out and manipulate as needed.

Code:
<table border=&quot;1&quot;>
<%
dim lngRecs,intCount, intColumnCounter
dim color1, color2, color3

' The total number of columns per recordset
intMaxGroups = 3

' Initialize the counter for determining which group we are on
intGroupingCounter = 0

' For testing purposes to see easily the results
color1 = &quot;#eeeeee&quot;
color2 = &quot;#aaaaaa&quot;
color3 = &quot;#cccccc&quot;

' Loop through your recordset ( you will want to replace this with your do while not rs.eof
For lngRecs = 1 to 144

	' check the grouping, which is each recordset 
	if intGroupingCounter = 0 then 
		Response.Write &quot;<tr>&quot;
	end if
	
	' increment the grouping counter
	intGroupingCounter = intGroupingCounter + 1

	' set the color based on the grouping
	color = &quot;color&quot; & ingGroupingCounter
	
	' display your recordset values
	Response.write &quot;<td bgcolor=&quot; & eval(color & intGroupingCounter) & &quot;>Field 1 Recordset &quot; & lngRecs & &quot;</td>&quot;
	Response.write &quot;<td bgcolor=&quot; & eval(color & intGroupingCounter) & &quot;>Field 2 Recordset &quot; & lngRecs & &quot;</td>&quot;

	' check to see if the grouping counter matches the maximum number of groups, which is set at the top of page.
	if intGroupingCounter = intMaxGroups then 

		' reset the grouping counter
		intGroupingCounter = 0
		
		' make a new row
		Response.Write &quot;</tr>&quot;
	end if

	' make sure here you do the rs.movenext
	' go to the next recordset in the database (replace with the &quot;loop&quot;)
Next
%>
</table>
My daily story these days:
9am [pc2] => 3p [flush] => 6p [pc2] => 10p [yawn2] 12a [hammer] => 1a [pc1] 3a [sleeping] => fri [cheers]
 
this may also gove you a bit of help.
sounds like it can be easlily changed to suite something to this effect
thread333-438314 onpnt
_________________________________________________________
for the best results to your questions: FAQ333-2924
Is your question a most FAQ?? Find out here FAQ333-3048
onpnt2.gif
[sup] [/sup]
 
Bgaines72, I tried your code and it worked as is. I modified it slightly to go with my database as you see it below. The problem is, everytime I run it I receive a
Code:
'loop' without 'do'
error. Is there something I'm missing here?
This is at the top of the page, before <head></head>
Code:
<%
dim intColumnCounter

' The total number of columns per recordset
intMaxGroups = 3

' Initialize the counter for determining which group we are on
intGroupingCounter = 0
%>
This is in the body.
Code:
<%
Do while not recordset1.eof

    ' check the grouping, which is each recordset 
    if intGroupingCounter = 0 then 
        Response.Write &quot;<tr>&quot;
    end if
    
    ' increment the grouping counter
    intGroupingCounter = intGroupingCounter + 1
    
    ' display your recordset values
    With Response
	     .write &quot;<td> &quot;
		 .write (Recordset1.Fields.Item(&quot;LocationID&quot;).Value)
		 .write &quot;</td>&quot;
    With Response
	    .write &quot;<td> &quot;
		.write  (Recordset1.Fields.Item(&quot;LocationTitle&quot;).Value)
		.write &quot;</td>&quot;

    ' check to see if the grouping counter matches the maximum number of groups, which is set at the top of page.
    if intGroupingCounter = intMaxGroups then 

        ' reset the grouping counter
        intGroupingCounter = 0
        
        ' make a new row
        Response.Write &quot;</tr>&quot;
    end if

    ' make sure here you do the rs.movenext
    ' go to the next recordset in the database (replace with the &quot;loop&quot;)
    recordset1.movenext
Loop
%>
 
Bgaines72,

Disregard that last post. I was able to fix it with a While...Wend loop. There were also a few naming convention mistakes I made, but everything's fixed and working properly. Thanks for your help.
 
Thanks.

In your above post, you don't have an End With after your With Response, which is probably part of the problem. My daily story these days:
9am [pc2] => 3p [flush] => 6p [pc2] => 10p [yawn2] 12a [hammer] => 1a [pc1] 3a [sleeping] => fri [cheers]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top