Print Page | Close Window

record set returns + row

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=4546
Printed Date: 30 March 2026 at 10:07am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: record set returns + row
Posted By: Badaboem
Subject: record set returns + row
Date Posted: 26 July 2003 at 4:21pm

How can I display records returned from the database next to eachother in tables and 4 colums? I'm trying to get the tables with the data next to eachother (4 tables) and then brake and start a new row of 4 tables etc.
You can see what I have right now below in the picture. I would like to list them next to eachother, instead of below eachother

<%
SQL = "SELECT * FROM LibrariesFiles WHERE CatID = " & Request("ID") & " ORDER BY FileName"
SET RS = Conn.Execute(SQL)
DO WHILE NOT RS.EOF
IF RS("Approved") = True THEN
%>

<table width="36%" border="0" cellspacing="1" cellpadding="1">
  <tr bordercolor="#000000" bgcolor="#CCCCCC">
    <td width="100">
      <%Response.Write ("<a href='library" & "/" & RS("Preview") & "'>" & "<img width=""100"" height=""100"" src='library" & "/" & RS("Preview") & "'>" & "</a>") %>
    </td>
    <td width="60%" align="left" valign="top">download:
      <%Response.Write ("<A HREF='fldetails.asp?id=" & RS("ID") & "'>" & RS("ProgramName") & "&nbsp;" & "</A>" & "<BR>" & "cinema 4d:" & RS("Version"))%>
      <br>
      date added:
      <%Response.Write (RS("DateUpdated"))%>
      <br>
      total downloads: <%Response.Write (RS("Downloads"))%></td>
  </tr>
</table>
<%END IF  
RS.MoveNext
LOOP
CloseDB strCon
%>
<br>


 

 

 




Replies:
Posted By: michael
Date Posted: 26 July 2003 at 4:31pm
Put all that in another table, then put a counter within your Recordset Loop when the counter hits a number that is dividable by 5 with no rest start a new row. (MOD function)

-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker


Posted By: Badaboem
Date Posted: 26 July 2003 at 5:19pm

hmm...I put it in a new table and searched for the mod functions on aspin that could allow this, but didn't find anything.

Could you be a little bit more specific?

Thanks in advance.



Posted By: Flamewave
Date Posted: 26 July 2003 at 7:38pm

The gallery that I made may be of some help to you for doing what you want, download and look at the code, I'm pretty sure it is more or less what you are looking for.

http://www.flameservers.com/asp_apps/gallery/gallery.asp - http://www.flameservers.com/asp_apps/gallery/gallery.asp



-------------
- Flamewave

They say the grass is greener on the other side, but if you really think about it, the grass is greener on both sides.


Posted By: michael
Date Posted: 26 July 2003 at 8:42pm
You can read about MOD on http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vaoprmod.asp - http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vaoprmod.asp

Basically you would to something like
If counter MOD 5 = 0 THEN
   'Begin a new row
ELSE
   'continue previous row
END IF

Hope that helps

-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker


Posted By: Badaboem
Date Posted: 27 July 2003 at 12:54am
Thanks again..I'm right at it


Posted By: Badaboem
Date Posted: 27 July 2003 at 9:32am

I've used flamewaves example and adjusted the code...it seems I'm still missing something here..

The page works without errors and does display rows and colums. The colums seem to work fine, but the rows show the existing items returned from the database over and over again without going to the next files (so it displays the first 4 items from the database, but doesn't show the next two remaining items in the next row)..

I've named the files: test 1, test 2 etc till test 6

See here: http://129.125.101.174/dark%20project/fldisplay.asp?page=1&id=4 - http://129.125.101.174/dark%20project/fldisplay.asp?page=1&id=4    (again refresh the page if you first receive an error).

What has to be added or changed in order to get the correct rows and colums returned?

Here is the adjusted code:


<%
'Make sure this page is not cached
Response.Expires = -1
Response.ExpiresAbsolute = Now() - 2
Response.AddHeader "pragma","no-cache"
Response.AddHeader "cache-control","private"
Response.CacheControl = "No-Store"

'new code gallery
'set to true if you are using a database and need a recordset
Const blnNeedRecordset = True

'Column and Row constants, the number of columns and rows you want displayed on each page
Const NUM_COLUMNS = 4
Const NUM_ROWS = 10

'old code

SET Conn = Server.CreateObject("ADODB.Connection")
SET rsDispItems = Server.CreateObject("ADODB.RecordSet")

SUB OpenDB(sConn)
 Conn.Open sConn
 SET rsDispItems.ActiveConnection = Conn
 rsDispItems.CursorType = AdOpenStatic
END SUB

SUB CloseDB(sConn)
 rsDispItems.Close
 Conn.Close
END SUB

OpenDB strCon

'new code gallery

'declare variables
Dim intOuterTableLoopCounter
Dim intInnerTableLoopCounter
Dim intTotalNumRecords
Dim rsDispItems
Dim intPageNum
Dim intNumFilePages
Dim intPageLoopCounter
Dim intItemCount

'get the current page number
intPageNum = Clng(Request.QueryString("Page"))
If intPageNum < 1 Then intPageNum = 1

'initilize the total number of records to 0
intTotalNumRecords = 0
%>
<%
SQL = "SELECT * FROM LibrariesCategories WHERE ID = " & Request("ID")
SET rsDispItems = Conn.Execute(SQL)
ID = rsDispItems("ID") %>
<% Response.Write (rsDispItems("CategoryName") & "&nbsp;" & "<A HREF='fladd.asp?CatID=" & Request("ID") & "'>Upload a File</A>")%>
<html>
 <head>
  <title>Page Title</title>
 </head>
 <body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0">
  <table align="center" width="95%" border="0" cellspacing="0" cellpadding="3">
   <tr>
    <td align="center"><h1><font size="2">download gallery</font></h1></td>
   </tr>
   
  <tr>
    <td>
      <%
If blnNeedRecordset Then
 'create a recordset and open it
 Set rsDispItems = Server.CreateObject("ADODB.Recordset")
 strSQL = "SELECT * FROM LibrariesFiles WHERE CatID = " & Request("ID") & " AND Approved=true ORDER BY FileName"
 'set the cursor type so we can move back and forth between records
 rsDispItems.CursorType = 1
 rsDispItems.Open strSQL, adoCon
 
 'if records were returned then get the page information
 If NOT rsDispItems.EOF Then
  'dynamicaly determine how many records will be displayed on the page
  rsDispItems.Pagesize = NUM_ROWS * NUM_COLUMNS
  'set the current page number
  rsDispItems.AbsolutePage = intPageNum
  If rsDispItems.EOF AND intPageNum > 1 Then rsDispItems.AbsolutePage = 1
  'get the number of pages
  intNumFilePages = rsDispItems.PageCount
  'get the number of records returned
  intTotalNumRecords = rsDispItems.RecordCount
 End If
Else
 intTotalNumRecords = NUM_ITEMS
 intNumFilePages = Clng(FormatNumber((((intTotalNumRecords - 1) / (NUM_ROWS * NUM_COLUMNS)) + 0.5), 0))
 'Response.Write intNumFilePages
 'Response.End
End If

intItemCount =  (intPageNum * (NUM_ROWS * NUM_COLUMNS)) - ((NUM_ROWS * NUM_COLUMNS) - 1)

'If there is more than 1 page of images then dispaly links to the other pages
If intNumFilePages > 1 Then

 'Display an image link to the last topic
 Response.Write vbCrLf & "<div class=""text"" align=""center"">Display Page:&nbsp;&nbsp;"

 'If we are not on the first page then display a previous link
 If intPageNum <> 1 Then Response.Write "<a href=""fldisplay.asp?Page=" & intPageNum - 1 & """>&lt;&lt;&nbsp;Prev</a>&nbsp;"

 'Loop round to display links to all the other pages
 For intPageLoopCounter = 1 to intNumFilePages

  'Display the numerical links to each page
  If intPageLoopCounter = intPageNum Then
   Response.Write vbCrLf & "&nbsp;" & intPageLoopCounter & "&nbsp;"
  Else
   Response.Write vbCrLf & "&nbsp;<a href=""fldispay.asp?Page=" & intPageLoopCounter & """>" & intPageLoopCounter & "</a>&nbsp;"
  End If

 Next

 'If we are not on the last page then display a next link
 If intPageNum <> intNumFilePages Then Response.Write "&nbsp;<a href=""fldisplay.asp?Page=" & intPageNum + 1 & """>Next&nbsp;&gt;&gt;</a>"
 Response.Write "<br><br>" & vbCrLf

End If

If intTotalNumRecords = 1 Then
 Response.Write "<p align=""center"">There is " & intTotalNumRecords & " item in this category.</p>" & vbCrLf 
Else
 Response.Write "<p align=""center"">There are " & intTotalNumRecords & " items in this category.<br>" & vbCrLf
 If intTotalNumRecords <> 0 Then
  If intPageNum = intNumFilePages Then
   Response.Write "Showing items " & intItemCount & " through " & intTotalNumRecords & " of " & intTotalNumRecords & ".</p>" & vbCrLf
  Else
   Response.Write "Showing items " & intItemCount & " through " & (intPageNum * (NUM_ROWS * NUM_COLUMNS)) & " of " & intTotalNumRecords & ".</p>" & vbCrLf
  End If
 End If
End If
%>
      <%
SQL = "SELECT * FROM LibrariesCategories WHERE ID = " & Request("ID")
SET rsDispItems = Conn.Execute(SQL)
ID = rsDispItems("ID") %>
      <table border="0" width="95%" align="center" cellspacing="10">
<%
 'row loop
 For intOuterTableLoopCoun



Posted By: Flamewave
Date Posted: 27 July 2003 at 10:15pm

I noticed that you open the rsDispItems several times throughout the code, when you could get by opening it only once. This is also probally whats messing up your results since you open the recordset again after the pagenumbers, recordnumbers, and the other variables are set. For the most part every time you open the recordset you are using the same sql string, so if you just open the recordset once instead of multiple times this should solve your problems, or at least is a good place to start.

edit: also I just noticed that you set the recordset = nothing in the middle of the double loop, this is not needed because the recordset is set to nothing after it is closed further down on the page.



-------------
- Flamewave

They say the grass is greener on the other side, but if you really think about it, the grass is greener on both sides.


Posted By: Badaboem
Date Posted: 28 July 2003 at 1:26am
It seems to work now..many many thanks Flamewave!!



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net