Display Records Horizontally ASP Script - ASP Web Pro
  Active Server Pages Programming by ASP Web Pro

ASP Scripts

DISPLAY RECORDS HORIZONTALLY

Ok, when it comes to displaying records from a database on a web page, we can all agree that using a table to organize your data is one of the most commonly used methods. Today, most websites use tables to display their records vertically. However, depending on the type of data that you are displaying or the layout of your page, you may need to display your records horizontally. So how do you do this. Actually it's not that hard.

The first thing you need to do is create a database called MyDatabase. Then, create a table called tblData with these fields:
ID - autonumber
Item - text field

Next, create a page called displayhoriz.asp and copy the below code into your page:

<!--#INCLUDE VIRTUAL="/includes/connection.asp" -->

<%
DIM mySQL, objRS
mySQL = "SELECT * FROM tblData"
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open mySQL, objConn

DIM recCount
IF Not objRS.EOF THEN
Response.Write "<table width='100%'>"
recCount = 0
Do UNTIL objRS.EOF

IF recCount Mod 3 = 0 THEN

IF recCount <> 0 THEN
Response.Write "</tr>"
Response.Write "<tr><td>"&objRS("Item")&"</td>"
ELSE
Response.Write "<td>"&objRS("Item")&"</td>"
END IF

recCount = recCount + 1
objRS.MoveNext
Loop

Response.Write"</tr></table>"
ELSE
Response.Write "Sorry, there are no records in our database."
END IF
%>

This script will return all of the records in your tblData table and display them in a table on your page. Plus, it will display three records horizontally in a table row and then end the current row, start a new row, and display three more records. If you want to display more records horizontally, simply change the "3" in this line: IF recCount Mod 3 = 0 THEN to however many records you want to display in each row.

Happy record displaying!

< Back to ASP Scripts


 

 

Main Menu
Home
ASP Scripts
ASP Tutorials
JavaScripts
Awards
Contact Us

Email This Page

Other Resources
ASP Web Hosting
Search Engine Submission
Programming Help

 

 

 

Other ASP Web Sites

Site Map

 

Last Updated:
22 March 2010