Wrox Programmer Forums
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old January 8th, 2005, 04:56 AM
Authorized User
Join Date: Sep 2004
Posts: 67
Thanks: 1
Thanked 0 Times in 0 Posts
Default ASP/SQL data in HTML table columns

Hi There
I'm just wondering how one would arrange data from a database into separate columns on a webpage.

At the moment I have a page with 3 table columns and I'm using 3 SQL queries and 3 lines of ASP code to populate each column.

For example:

set rsColumnOne = objConn.Execute("SELECT * FROM table WHERE row BETWEEN '1' and '10'")

set rsColumnTwo = objConn.Execute("SELECT * FROM table WHERE row BETWEEN '11' and '20'")

set rsColumnThree = objConn.Execute("SELECT * FROM table WHERE row BETWEEN '21' and '30'")

This feels quite messy and considering I want to add even more columns to the page the amount of SQL queries are going to get out of control (not to mention the load it would place on the server and the extra processing time).

Surely there is a much easier way where I can use the one query then use some ASP code to distribute parts of the query result to different sections of my HTML tables?

Any help would be greatly appreciated!!
Old January 8th, 2005, 05:55 AM
Friend of Wrox
Join Date: Oct 2003
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to madhukp

I did not understand the correct HTML structure (in what format data will come in the columns ?). Anyway, check whether the following logic will help.

Dim iNumCols
iNumCols = 3

Dim arrContent(3)

qry="SELECT <field_list> FROM table"

set rs = objConn.Execute(qry)

if(not(rs.Eof or rs.Bof))

        'formulate the piece of HTML corresponding to this record. Let that be stored in a variable strContent.
        If(rs("row")>=1 and rs("row")<=10) Then
            arrContent(1)=arrContent(1) & strContent
        else if(rs("row")>=11 and rs("row")<=20) Then
            arrContent(2)=arrContent(2) & strContent
        else if(rs("row")>=21 and rs("row")<=30) Then
            arrContent(3)=arrContent(3) & strContent
        end if

    Dim iLoop
    Response.Write "<table class=""<class for table>""><tr>" & vbcrlf
    for iLoop = 1 to iNumCols
        Response.Write "<td class=""<class for column>"">" & arrContent(iLoop) & "</td>" & vbcrlf
    Response.Write "</tr></table>"
end if

When the number of columns change you need to add more else if blocks. You have to change the iNumCols and the array subscription.
Old January 9th, 2005, 07:02 AM
Authorized User
Join Date: Sep 2004
Posts: 67
Thanks: 1
Thanked 0 Times in 0 Posts

Thank you very much for your help madhukp!

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to set indexes on columns in a data table hdewees VB Databases Basics 1 June 5th, 2006 02:42 PM
constructing a HTML table from xml data using xslt rameshnarayan XSLT 0 September 19th, 2005 06:53 AM
html table data single line -- Solved rupen HTML Code Clinic 1 August 8th, 2005 02:26 PM
Getting the data in columns - like Pivot Table merguvan Access VBA 4 February 29th, 2004 02:31 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.