Soren Winslow Soren Winslow
Display Data In Newspaper Column Format Table
How to display data results from a query in a multiple column table listing the data vertically from top to bottom, similarly to newspaper format.
Let's say that you are creating an employee list of employees and phone numbers and wish to have the results sorted in three columns verticaly. For example records 0 - 10 would be in the first column, 11 - 21 in the second and 22 - 32 in the last (third column). So, basicly it displays in "Newspaper Column" format.
Here is a process that can do that for you and even give you the flexibility to change only the number of columns and the data that is displayed. Like a grid, x will represent horizontal and y represents vertical.

Here is the code to display data results in a three column format:
<%

SqlStr = "SELECT Employee, PhNum " & _
           "FROM TheTable " & _
           "ORDER BY Employee "
 
 Set objRS = Server.CreateObject ("ADODB.RecordSet")
 objrs.Open SqlStr, ConStr, adOpenStatic, adLockOptimistic,adCmdText
   
   'This is how many columns you want
   NumCols = 3

   NumRecs = objrs.RecordCount
   NumEachCol = NumRecs/NumCols
   
   If (NumRecs Mod NumCols) > 0 Then
      TempNumRecs = NumRecs + (NumCols-(NumRecs Mod NumCols))
      NumEachCol = TempNumRecs /NumCols
   End If

   Response.Write "<table>"

   Response.Write "<tr>"
   For x = 0 to NumCols - 1
      'Column Headings
      Response.Write "<td>Employee</td>"
      Response.Write "<td>Phone Num</td>"
   Next
   Response.Write "</tr>"

   For y = 0 to NumEachCol-1
      Response.Write "<tr>"
      For x = 0 to NumCols-1
         'Calculate the next record number in the row
         RecNum = y + (NumEachCol * x)
         'Check to make sure we haven't run out of records
         If RecNum < NumRecs Then
            objrs.MoveFirst
            objrs.Move RecNum
            Response.Write "<td>" & objrs("Employee") & "</td>"
            Response.Write "<td>" & objrs("PhNum") & "</td>"
         Else
            Response.Write "<td> </td>"
            Response.Write "<td> </td>"
         End If
      Next
      Response.Write "</tr>"
   Next

   Response.Write "</table>"

 objrs.Close
 Set objRS = Nothing

%>

               

Here is a similar example of the code above. Because I do not have an employee database loaded on this domain, I will run a query to show the last 50 unique pages viewed and order them by the last date and time they were viewed. Because of available page space, I will run it in a two column format.
Notice that the results read top to bottom in each column before spilling over to the next column.
Date Time - PageDate Time - Page
 11/20/2008 13:01 - VertCols.asp  11/20/2008 11:25 - Photos.asp?Ga...oncept.jpg 
 11/20/2008 13:00 - Chargers.asp  11/20/2008 11:23 - GuestBook.asp 
 11/20/2008 13:00 - GuestBookSign...xxCxxExxFx  11/20/2008 11:17 - TriumphNews.asp 
 11/20/2008 12:59 - GuestBookSign.asp  11/20/2008 11:16 - Squidoo.asp 
 11/20/2008 12:58 - Triumph.asp  11/20/2008 11:02 - UtahJazzEbay.asp 
 11/20/2008 12:55 - ColorChart.asp  11/20/2008 10:39 - GuestbookView.asp 
 11/20/2008 12:55 - Photos.asp  11/20/2008 10:39 - GuestBookSign...Err=xBxxFx 
 11/20/2008 12:54 - TriumphModels.asp  11/20/2008 10:34 - Ebay.asp?eBayList=EbaySearch 
 11/20/2008 12:52 - DST.asp  11/20/2008 10:14 - NBAScoresSche...am=Seattle 
 11/20/2008 12:50 - TriumphLogos.asp  11/20/2008 10:07 - ASPScriptsRSSList.asp 
 11/20/2008 12:48 - Divisor.asp  11/20/2008 10:04 - ChrDec.asp 
 11/20/2008 12:47 - UtahJazz.asp  11/20/2008 09:44 - Photos.asp?Ga...CN1212.JPG 
 11/20/2008 12:44 - RSSDateFunction.asp  11/20/2008 09:44 - RomanNumerals.asp 
 11/20/2008 12:40 - UtahJazzNews.asp  11/20/2008 09:35 - Photos.asp?Ga...ph-TSX.jpg 
 11/20/2008 12:36 - Calendar.asp  11/20/2008 09:15 - TriumphEbay.asp 
 11/20/2008 12:34 - Photos.asp?Ga...otorcycles  11/20/2008 09:08 - RSSReader.asp...iewRSS.asp 
 11/20/2008 12:27 - FredThompsonNews.asp  11/20/2008 08:37 - Themes.asp?Th...Basketball 
 11/20/2008 12:23 - RSSReader.asp...hopRSS.asp  11/20/2008 08:35 - SlideShow.asp?Gallery=Cars 
 11/20/2008 12:01 - MultiSelect.asp  11/20/2008 08:00 - TriumphYouTube.asp 
 11/20/2008 11:57 - TriumphMotorcycles.asp  11/20/2008 07:20 - NBAScoresSche...Team=Miami 
 11/20/2008 11:54 - CafePress.asp  11/20/2008 06:57 - Photos.asp?Ga...per_b_.jpg 
 11/20/2008 11:54 - SiteMap.asp  11/20/2008 06:49 - Photos.asp?Ga...alis-Flood 
 11/20/2008 11:54 - Default.asp  11/20/2008 05:25 - RSSReader.asp...ookRSS.asp 
 11/20/2008 11:50 - RSSReader.asp...ewsRss.asp  11/20/2008 05:02 - Photos.asp?Ga...Tourer.jpg 
 11/20/2008 11:40 - Photos.asp?Ga...master.jpg  11/20/2008 04:48 - Photos.asp?Ga..._angle.jpg 

© 1967 - 2008 Soren Winslow