RE: [PHP] looping

From: Date: Mon, 15 Jan 2001 21:52:11 +0000
Subject: RE: [PHP] looping
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-34685@lists.php.net to get a copy of this message
Thanks, (Ignacio) I came up with this <snip> $counter++; if ($counter > "4") { $counter = "1"; echo "</tr><tr bgcolor=" . $colors[ $i ++ % count( $colors ) ] . ">"; } </snip> Jerry Lake -----Original Message----- From: Ignacio Vazquez-Abrams [mailto:ignacio@openservices.net] Sent: Monday, January 15, 2001 1:22 PM To: Jerry Lake Cc: PHP List Subject: Re: [PHP] looping On Mon, 15 Jan 2001, Jerry Lake wrote: > excuse my density today > my brain is still in weekend mode > > how would I make this loop put 4 or 5 items (haven't decided) > per line instead of just one item and the checkbox on each line? > > <snip> > echo "<table border='1' cellpadding='2' > cellspacing='2'>"; > > while($myrow = mysql_fetch_array($result2)) > { > $name = $myrow["name"]; > $personal_cost = $myrow["personal_cost"]; > $small_cost = $myrow["small_cost"]; > $large_cost = $myrow["large_cost"]; > $category = $myrow["category"]; > > echo "<tr>"; > echo "<td>"; > echo $name; > echo "</td>"; > echo "<td><input type=checkbox name=topping value=".$cost.">".$cost."</td>"; > echo "</tr>"; > } > echo "</table>"; > </snip> > > Jerry Lake > Join the club :) <?php define('PERLINE', 4); // or 5, depending on taste ... echo "<table border='1' cellpadding='2' cellspacing='2'>"; echo "<tr>"; $i=0; $numrows=mysql_num_rows($result2); while($myrow = mysql_fetch_array($result2)) { ++$i; ... echo "<td>"; ... echo "</td>"; if (!($i%PERLINE) and ($numrows!=$i)) { echo("</tr><tr>"); }; }; echo "</tr>"; echo "</table>"; ?> -- Ignacio Vazquez-Abrams <ignacio@openservices.net>

« previous php.general (#34685) next »