Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

ASP.NET Forum


You are currently viewing our ASP.NET Forum as a guest. Please register to participate.
Login



Reply
Formatting database info into tables
Old 11-30-2006, 04:46 PM Formatting database info into tables
Super Talker

Posts: 116
Trades: 0
Hi there,

I have a real question that's baffling the heck out of me.

How do I format a table that is five cells across where EACH CELL contains the information from a database record?

An example of what I'm trying to do is at: http://www.musiciansatlas.com/pages/jukebox2006.asp

I hope this makes sense....

When you go to this page, each song category is a database record that contains the image of the artist plus the artist information and a link to their song.

Right now, all this is hardcoded in. I'm able to load all the iframe menus in ASP from a While loop reading the database.

But now, I want to actually draw the page with a table where EACH CELL contains a database record of the winner. So the table will be FIVE RECORDS across and as many down to complete the table.

To better clarify: Americana/Maura Fogarty is one record, followed by Blues/Jimmy Norton which is another record.

Any suggestions? For loops don't work because it just draws one record five times across the page.

This would be a MAJOR breakthrough for me as "database" is my middle name.

DonnaZ
DonnaZ is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-30-2006, 06:00 PM Re: Formatting database info into tables
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Two loops

one outer loop that builds the table rows until RS.EOF

one inner loop 0 to 4 to build the cells and step through the RS

at the end of the outer loop add a number of blank cells to fill the last row

this is the code I wrote to do exactly that for a shopping cart I designed (now converted to CSS)
Code:
If iPageCount = 0 Then
	Response.Write "No Products to display"
Else
with response
if not CatTop then 
.write "<span class='center'>"
.write "<a href='"
if GetPath(2) <> "" then
.write "/"
.write GetPath(2)
end if
.write "/"
.write GetPath(1)
.write "/"
.write "?ss="
.write CatID 
.write "' "
.write " title='View as a slide show' >"
.write "Slide Show"
.write "</a>" & vbCrLf
.write "</span>" & vbCrLf
end if
end with
	' Move to the selected page
	objRS.AbsolutePage = iPageCurrent

	with response
	' Start output with a page x of n line
	.write "<div align='left'>" & vbCrLf
	
	' Loop through our records and ouput 1 row per record
	iRecordsShown = 0
	.write "<table width='80%'align='center' border='0'>" & vbCrLf
	'response.write "<tr>" & vbCrLf
if bShowThumbs = True then
	
	Do While iRecordsShown  < iPageSize
	if objRS.RecordCount > 0 then    '1
	if not objRS.EOF or not objRS.BOF then
	for i = 0 to intColCount -1
	if i = 0 then response.write "<tr>"  & vbCrLf
	.write "<td width='25%'>"
	
	.write "<a class='img' href='"
	.write strShopFolder
	.write "?item="
	.write CInt(objRS.Fields("id")) &  "'>" 
	.write "<img src='"
	
if objRS.Fields("pic_path") <> "" then
	CheckPic1 = CheckPrefix(objRS.Fields("pic_name"))
if not bPicFound then
	CheckPic1 = CheckSuffix(objRS.Fields("pic_name"))
end if
	.write CheckPic1
	.write "/images/"
	.write "no_image.gif"
end if
	.write "' alt='" & objRS.Fields("pic_caption") & "' >" & vbCrlf
	.write "</a>" & vbCrLf
	strItem = WordWrap(objRS.Fields("pic_caption"),15)
	.write "<br >" & vbCrLf
	.write "<span class='tncaption'>" & vbCrLf
	if strItem <> "" then ' strItem = "&nbsp;"
	.write "<a href='"
	.write strShopFolder
	.write "?item="
	.write CInt(objRS.Fields("id")) &  "'>" 
	.write strItem & vbCrLf
	.write "</a>" & vbCrLf
	end if
	.write "<br >" & vbCrLf
	.write "</span>" & vbCrLf
	.write "</td>" & vbCrLf
	
		iRecordsShown = iRecordsShown + 1
		objRS.MoveNext
		if objRS.eof then 
					flag = true
				for j = i + 1 to intColCount - 1
					.write "<td>&nbsp;</td>" & vbCrLf
					i = intColCount - 1
				next
		end if
	if i = intColCount - 1  then .write "</tr>"  & vbCrLf
	if flag = true then exit for
	next 
	end if     ' EOF BOF 			
	end if
	if flag then exit do 
	Loop
	.write "</tr>" & vbCrLf
else
'not showing thumbnails
	'with response
		.write "<tr>"
		.write "<th>"
		.write "Order Code"
		.write "</th>"
		
		
	'end with
end if  
	end with
End If



	response.write "</table>" & vbCrLf
	response.write "</div> <!--aligned-->" & vbCrLf
Most of the variables are named logically so you can tell what their function and values do. Such as "intColCount" is the number of columns across the page.

Don't worry about many of the UDFs they are mainly my way of writing modular code, the important bits are the sections writing the table tags.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-02-2006, 05:21 PM Re: Formatting database info into tables
Super Talker

Posts: 116
Trades: 0
Thanks alot!

DZ
DonnaZ is offline
Reply With Quote
View Public Profile
 
Old 12-02-2006, 08:06 PM Re: Formatting database info into tables
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
The other angle you can use (and I find works much faster, if done properly) is to use the little-known GetRows() property to write your database records to a two-dimensional array and then spit out the array.

http://www.asp101.com/samples/db_getrows.asp

You'll have to mod that code somewhat for speed reasons, but it should at least work.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Reply     « Reply to Formatting database info into tables
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.20098 seconds with 12 queries