Re: hrm..loop trouble

From: Date: Wed, 19 Sep 2001 21:44:14 +0000
Subject: Re: hrm..loop trouble
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-67906@lists.php.net to get a copy of this message
Modulus will come in handy here, here's an example use : <table> <tr> <?php $result = mysql_query("SELECT foo FROM bar"); $i = 0; while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) { echo "\t<td>". $row['foo'] ."</td>\n"; if (($i++ % 5) === 4) { echo "</tr>\n<tr>\n"; } } ?> </tr> </table> Regards, Philip Olson On Wed, 19 Sep 2001, Kurth Bemis wrote: > i'm trying to get a chunk of code to look 5 times then print > something..then look 5 time more.... > > I really want to loop 5 times (making 5 cells) then print </tr><tr>then > loop 5 more times for 5 cells...until the count is reached....like if i > have 22 things i want to have 4 rows of five and one row of two...get what > i'm trying to do? > > heres the code that i have so far > > <?php > while ($arraycnt <= (count ($typearray)-1)){ > $type = $typearray[$arraycnt]; //grab a first chair in array > > $sqlquery = "SELECT * FROM chairs WHERE type = '$type'"; //construct sql > > query > $result=mysql_query($sqlquery,$db); > > while ($tempcnt <= 5){ > print "<tr bgcolor=\"#ffffff\">"; > while ($myrow = mysql_fetch_array($result)) { > print "<td align=\"center\"><img > src=\"/img/thumbs/".$myrow[modelnum]."_1.gif\" border=\"0\" > alt=\"\"><br>Model $myrow[modelnum]</td>"; > } //close cell loop > $tempcnt++; > print "</tr>"; > } //close second while loop > $arraycnt++; > } //close first while loop > ?> > > look at http://www.strawhillchairs.com/cat/index.php > > to see what i'm trying to do.... > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#67906) next »