Re: creating subheads in an array

From: Date: Tue, 31 Oct 2000 03:04:17 +0000
Subject: Re: creating subheads in an array
Groups: php.general 
Request: Send a blank email to php-general+get-22815@lists.php.net to get a copy of this message
Addressed to: Tom Beidler <tbeidler1@home.com> php-general@lists.php.net ** Reply to note from Tom Beidler <tbeidler1@home.com> Mon, 30 Oct 2000 11:13:03 -0800 > > I've setup a site that dumps a product list into a table. There are > approximately 500 products and the client prefers that the initial page > shows all 500 products. Each product has a category, description, > application, part number, price and comments field. I'm trying to keep > horizontal space to a minimum, so currently I don't list category. What I > would like to do is create a table and have a separate row inserted for > each category to break up the items. > > So, when I display all of the products sorted by category, each new > category would have a row inserted before it with its category name. When > a new category would start, a new row would be inserted before with the > category name, continuing down for however may categories are present. > > Can this be done? I'm currently using alternating colored rows and I > thought it might be similar. Maybe too complex though. $Result = mysql_Query( "SELECT Category, Var1, Var2... " . "FROM Table " ); $OldCategory = ''; # Holder for current category value $I = 0; # Counter for alternating colors while( list( $Category, $Var1, $Var2... ) = mysql_fetch_row( $Result )) { if( $Category != $OldCategory ) { # New catagory, need to paint it # Set $Color to proper background color, increment $I echo( "<TR bgcolor=$Color><TD colspan=?? align=center>$Category" . "</TD></TR>\n" ); $OldCategory = $Category; } # Paint the data row # Set $Color to proper background color, increment $I echo( "<TR bgcolor=$Color><TD>$Var1</TD><TD>$Var2</TD>...</TR>" ); } Rick Widmer Internet Marketing Specialists www.developersdesk.com

« previous php.general (#22815) next »