Jump to content

do-while loop won't run after first execution


alexisfromboston

Recommended Posts

Below is the code for the section of the page im working on.

 

I am creating a horizontal nav bar with drop down menus - much like this: <a href="http://www.htmldog.com/articles/suckerfish/dropdowns/example/"> DROP DOWNS EXAMPLE</a>

 

All of the content in the nav I currently have in two tables a categories table and a subcategories table:

TABLE 1

 

CATID= 1

CNAME = HOUSES

 

CATID = 2

CNAME = APARTMENTS

 

TABLE 2

 

SCATID = 1

CATREF = 2

SCNAME = BIG APARTMENTS

 

SCATID = 2

CATREF = 1

SCNAME = SMALL HOUSES

 

 

In both cases the ID's are the unique primary keys. in table 2 CATREF refers to the category it belongs too.

 

Im trying to have the subcategories automatically go below the main categories but right now with the code I have below it only populates the first list. and the rest are blank.

 


<ul id="nav">
<?php do { ?>
  <li class="firstmenu"><a href="<?php echo $row_TopCategories['CATID']; ?>" >
  	<?php echo $row_TopCategories['CNAME']; ?></a>
       
     
                <ul>
                    <?php do { ?>
        	          <?php if ($row_SubCategories['CATREF'] == $row_TopCategories['CATID']) { 
		    echo "<li><a href='#'>".$row_SubCategories['SCNAME']."</a></li>"; } ?>
                   <?php } while ($row_SubCategories = mysql_fetch_assoc($SubCategories)); ?>
               </ul>
 </li>
<?php } while ($row_TopCategories = mysql_fetch_assoc($TopCategories)); ?></ul>

Link to comment
Share on other sites

I simplified the code as much as possible since I realized what I was saying doesnt make sense -

 

<?php require_once('../Connections/TestHost.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_TestHost, $TestHost);
$query_TopCategories = "SELECT * FROM categories ORDER BY CNAME ASC";
$TopCategories = mysql_query($query_TopCategories, $TestHost) or die(mysql_error());
$row_TopCategories = mysql_fetch_assoc($TopCategories);
$totalRows_TopCategories = mysql_num_rows($TopCategories);

mysql_select_db($database_TestHost, $TestHost);
$query_SubCategories = "SELECT * FROM subcategories ORDER BY SCNAME ASC";
$SubCategories = mysql_query($query_SubCategories, $TestHost) or die(mysql_error());
$row_SubCategories = mysql_fetch_assoc($SubCategories);
$totalRows_SubCategories = mysql_num_rows($SubCategories);
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Free Pass Coupon</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">

</head>

<body>

<ul id="nav">

    
<?php do { ?>
  <li class="firstmenu"><a href="<?php echo $row_TopCategories['CATID']; ?>" id="grab<?php echo $row_TopCategories['CATID']; ?>" class="firstmenuHL">
  	<?php echo $row_TopCategories['CNAME']; ?></a>
       
     
        <ul>
        
        	 <?php do { ?>
        	<?php if ($row_SubCategories['CATREF'] == $row_TopCategories['CATID']) { 
		echo "<li><a href='#'>".$row_SubCategories['SCNAME']."</a></li>"; } ?>
           <?php } while ($row_SubCategories = mysql_fetch_assoc($SubCategories)); ?>
         </ul>
        </li>
  <?php } while ($row_TopCategories = mysql_fetch_assoc($TopCategories)); ?></ul>
</body>



</html>
<?php
mysql_free_result($TopCategories);

mysql_free_result($SubCategories);
?>

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.