Re: php/mysql horizontal listing query

From: Date: Wed, 27 Jun 2001 01:55:30 +0000
Subject: Re: php/mysql horizontal listing query
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-9853@lists.php.net to get a copy of this message
on 6/26/01 10:43 AM, Matt Nigh at matt@mattnigh.com wrote: > I need a section of a record label site with a releases section listed > horizontally but here's the twist: after every 4 releases, I want the > releases to move to the next columns below. > > ex. > release#1, release#2, release#3, release#4 > release#5, release#6 Basically you need to use the modulus operator. Here's a rough example (untested): <?php // set number of rows $n = 4; // initialize cell count $c = 0; // start table code (omitted) echo '<tr>'; // perform your query (omitted) while ($row = mysql_fetch_array($query,$conn)) { // make a new row if we reached the end of one // but don't do it for the first row. if ($c % $n == 0 && $c >= $n) { echo '</tr><tr>'; } echo '<td>'; // spit out all your mysql fields (omitted) echo '</td>'; // increment your cellcounter; $c++; } // make sure you don't have a malformed table while ($c % $n != 0) { echo '<td>&nbsp;</td>'; $c++; } echo '</tr>'; // end table code (omitted) ?> Hope that helps. Sincerely, Paul Burney ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Paul Burney Webmaster && Open Source Developer UCLA -> GSE&IS -> ETU (310) 825-8365 <webmaster@gseis.ucla.edu> <http://www.gseis.ucla.edu/> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

« previous php.db (#9853) next »