note 28077 added to control-structures.do.while
| From: | arathorn at ifrance dot com | Date: | Wed, 01 Jan 2003 01:32:38 +0000 |
| Subject: | note 28077 added to control-structures.do.while | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-41532@lists.php.net to get a copy of this message | ||
I love 'do ... while' because it is easy to put html in a php code break.
Also see an example to display Categories and Subcategories with only 1 DB request (most coders use
two)
<?php
mysql_select_db($DB_name, $Connection);
$query = "
SELECT * FROM Cat, SubCat
WHERE Cat.cat_id = SubCat.scat_id
ORDER BY Cat.cat_order, SubCat.scat_order";
$Display = mysql_query($query, $Connection) or die(mysql_error());
$row = mysql_fetch_assoc($Display);
$totalRows_Display = mysql_num_rows($Display);
// General Loop Start
// Start Categories counter
$cat_prec = -1; // must be < to Min(Cat.cat_id)
do {
// Categories Loop Start
/* Show only 1 time the Category, for all Subcat under the same Category*/
if ($row['cat_id'] != $cat_prec)
{
?>
HTML code to display Category
<?php echo $row['cat_name'] ?>
HTML code to display Category
<?php
// Upgrade Categorie Counter
$cat_prec = $row['cat_id'];
} // Categories Loop END ?>
HTML code to display SubCategories
<?php echo $row['scat_name'] ?>
HTML code to display SubCategories
<?php } while ($row = mysql_fetch_assoc($Display));
// END OF GLOBAL LOOP
mysql_free_result($Display);
?>
--
http://www.php.net/manual/en/control-structures.do.while.php
http://master.php.net/manage/user-notes.php?action=edit+28077
http://master.php.net/manage/user-notes.php?action=delete+28077
http://master.php.net/manage/user-notes.php?action=reject+28077