note modified in by philip

From: Date: Sun, 16 Mar 2003 02:38:05 +0000
Subject: note modified in by philip
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-45374@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); ?> --was-- http://www.php.net/manual/en/.php

« previous php.notes (#45374) next »