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

© 1967 - 2017 Soren Winslow