RE: [PHP] mysql php - while loops

From: Date: Thu, 28 Feb 2002 06:24:50 +0000
Subject: RE: [PHP] mysql php - while loops
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-86538@lists.php.net to get a copy of this message
Thanks for the reply. This is what I came up with and it appears to work. Thoughts? Craig ><> westerman@chanuteks.com ******************************** $count = 1; while ($data = mysql_fetch_array($results)) { ?> <p><?=$data["date"]?> - <?=$data["orangeprice"]?> - <?=$data["appleprice"]?> - <?=$data["pearprice"]?></p> <? $count++; if ( $count == 5 ) { ?><IMG SRC="grape.gif"><br><?php } elseif ( $count == 9 ) { ?><IMG SRC="cherry.gif"><br><?php } } ****************************************** -----Original Message----- From: Martin Towell [mailto:martin.towell@world.net] Sent: Tuesday, February 26, 2002 6:51 PM To: 'Craig Westerman'; php-general-list Subject: RE: [PHP] mysql php - while loops with a bit of cheating... use a table... (nb: this code not tested, but logic has) <table> <? $results = mysql_query("SELECT ID, date, appleprice, orangeprice, pearprice FROM fruits"); $i = 0; $cols = 4 while ($data = mysql_fetch_array($results)) { if ($i % $cols == 0) echo "<tr>" ?> <td><?=$data["date"]?> - <?=$data["appleprice"]?><br> <?=$data["orangeprice"]?> - <?=$data["pearprice"]?></td> <? if ($i % $cols == $cols-1) echo "</tr>"; $i++; } ?> </table> -----Original Message----- From: Craig Westerman [mailto:westerman@chanuteks.com] Sent: Wednesday, February 27, 2002 11:43 AM To: php-general-list Subject: [PHP] mysql php - while loops The following lists 12 items from a fruits table. $results = mysql_query("SELECT ID, date, appleprice, orangeprice, pearprice FROM fruits"); while ($data = mysql_fetch_array($results)) { ?> <p><?=$data["date"]?> - <?=$data["appleprice"]?> - <?=$data["orangeprice"]?> - <?=$data["pearprice"]?></p> <? } How would I modify the loop to display 4 items then a row of fruit images then 4 more items then another row of different fruit images and then finally finish the loop displaying the final 4 items? Thanks Craig ><> westerman@chanuteks.com

« previous php.general (#86538) next »