When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles
Message Board
Related Web Technologies
User Tips!
Coding Tips

Sample Chapters
Commonly Asked Message Board Questions
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Stump the SQL Guru!
XML Info
Author an Article
ASP ASP.NET ASP FAQs Message Board Feedback
Print this page.
Published: Wednesday, November 17, 1999

Formatting Database Results into Newspaper-Style Columns, Part 2

By Claude Rubinson

In Part 1 we presented the code. In Part 2, we are going to discuss limitations and customizations.

- continued -

The presented method of dimensionalizing the multidimensional array against the number of records and the number of columns creates an inordinate number of superfluous elements if the number of columns is greater than one. Specifically, the number of superfluous elements equals the product of the number of records and the number of columns minus the number of records. The solution is to dimensionalize the first element of the array against the quotient of the number of columns minus one and the number of records. This will cause a 'division by zero' error if the number of columns equals one, so a check for the number of columns is included.

if intColumns > 1 then
	redim DataArray(rs.RecordCount/(intColumns-1),intColumns)
	redim DataArray(rs.RecordCount,intColumns)
end if

There is one undesirable aspect of the script; depending upon the requirements of your particular project, this may or may not be serious. Under certain conditions, the number of rows per column may vary. Ideally, the only variance in column length would be with the last column, but the current script balances the number of records across all columns. The result is that sometimes the one column may be shorter than that which follows it. To date, I have been unable to develop an algorithm that corrects this flaw; if someone else is able to, I would appreciate your sharing it.

The script is rather flexible and permits a wide range of customization. Header and footer rows may easily be added to the table by passing the number of columns to the COLSPAN attribute. Further customization is possible by adding additional dimensions to the multidimensional array. The next image presents a customized version of the script and the resulting output.

A customized version
View the code

Finally, note that the script may easily be converted into a subroutine. By passing the number of desired columns to the subroutine (from, say, an HTML form), the custom formatting of results is available.

Happy Programming!


  • Download the complete code in text format

  • ASP.NET [1.x] [2.0] | ASPFAQs.com | Advertise | Feedback | Author an Article