dubfoundry Posted August 3, 2009 Share Posted August 3, 2009 The following code suppose to output a category sub category list..it only out puts a single row under each category it doesnt do all the subcats...here is the final code i have...i cant figure out why it would only print one row...The sql statement works perfectly in phpadmin.. if(isset($_GET['upload'])&& !isset($_GET['edit_gal'])){ require_once('upload.php'); }elseif(isset($_GET['edit_gal'])){ mysql_select_db($database, $makeconnection); $query = "SELECT * FROM tbl_gallery g, tbl_subgallery s WHERE s.gal_id=g.gal_id ORDER BY s.gal_id"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_assoc($result); $prev_section = null; $sectionHeading = false; //echo '<table border="1" cellpadding="5" cellspacing="2">'; do{ if($prev_section != $row['gal_name']) { $prev_section = $row['gal_name']; $sectionHeading = false; } if(!$sectionHeading) { echo '<h1>' . $row['gal_name'] . '</h1>'; $sectionHeading = true; } else { echo $row['subgal_name'].'<p> </p'; } }while($row = mysql_fetch_assoc($result)); } } Link to comment https://forums.phpfreaks.com/topic/168691-category-subcategory-listcode-stumper/ Share on other sites More sharing options...
ram4nd Posted August 6, 2009 Share Posted August 6, 2009 you have to stick sub cat getting into another while, you are the first one who writes php code like this Link to comment https://forums.phpfreaks.com/topic/168691-category-subcategory-listcode-stumper/#findComment-892306 Share on other sites More sharing options...
Psycho Posted August 6, 2009 Share Posted August 6, 2009 if(isset($_GET['upload'])&& !isset($_GET['edit_gal'])) { require_once('upload.php'); } elseif(isset($_GET['edit_gal'])) { mysql_select_db($database, $makeconnection); $query = "SELECT * FROM tbl_gallery g, tbl_subgallery s WHERE s.gal_id=g.gal_id ORDER BY s.gal_id"; $result = mysql_query($query) or die(mysql_error()); $sectionHeading = false; while ($row = mysql_fetch_assoc($result)) { if($sectionHeading != $row['gal_name']) { echo "<h1>{$row['gal_name']}</h1>\n"; $sectionHeading = $row['gal_name']; } echo "<p>{$row['subgal_name']}</p>\n"; } } Link to comment https://forums.phpfreaks.com/topic/168691-category-subcategory-listcode-stumper/#findComment-892319 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.