To read the article online, visit http://www.4GuysFromRolla.com/webtech/111799-1.2.shtml

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.

Limitations
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)
else
	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.

Customization
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!


Attachments

  • Download the complete code in text format


  • Article Information
    Article Title: Formatting Database Results into Newspaper-Style Columns
    Article Author: Claude Rubinson
    Published Date: Wednesday, November 17, 1999
    Article URL: http://www.4GuysFromRolla.com/webtech/111799-1.2.shtml


    Copyright 2017 QuinStreet Inc. All Rights Reserved.
    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers