Nested while loop help

[php]<?php 
// Query for outter loop (i.e. subcategories)
	$query_subcategories = "SELECT * FROM collections WHERE collRelatedID = 
							( SELECT collID FROM collections WHERE collType =\"".$_GET['recordID']."\")
							ORDER BY collID ASC";

// Get Results!
	$result_subcategories = mysql_query($query_subcategories, $basicdb) or die(mysql_error());

// Count 'em
	$row_count_subcat = mysql_num_rows($result_subcategories);

// Alright - time for the outter loop
	while($row_subcategories = mysql_fetch_array($result_subcategories))
	{
		// Back to HTML for now...
		?>[/php]
    [code]<tr>
    	<td colspan="2"> <h2> <?php echo $row_subcategories['collType']; ?> </h2> </td>
    </tr>[/code]
        [php]<?php 
		
		// Define query for subloop (i.e. docs for the subcategory)
	$query_docs = "SELECT docTitle, docLocation, docDesc FROM documents 
					WHERE docType = 
					(SELECT collType FROM collections WHERE collID=\"".$row_subcategories['collID']."\")";
	
	// GET RESULTS!!!
	$results_docs = mysql_query($query_docs, $basicdb) or die(mysql_error());
	
	// Count 'em
	// $row_count_docs = mysql_num_rows($results_docs);
	// echo $row_count_docs;
	// echo $query_docs;
		?>
    		<?php
	// inner loop
	while($row_docs = mysql_fetch_array($results_docs))
	{
		// back to HTML 
	?>[/php]
    [code]<tr>
    	<td width="20px"> &nbsp; </td>
        <td width="580px">
        	<a href="documentationmaterials.php?recordID=[/code][php]<?php echo row_docs['docLocation']; ?>[/php]"> 
           [php] <?php echo row_docs['docTitle']; ?> [/php]
           [code] </a>
         </td>
     </tr>
     <tr>
     	<td width="20px"> &nbsp; </td>
        <td width="580px">[/code]
		[php]<?php echo row_docs['docDesc']; ?>[/php] [code]<hr />
        </td>
     </tr>[/code]
     [php]<?php 
	 	// end subloop
		
	}
	?>
    <?php
	 	// Finish top-loop html stuff
	?>[/php]
    [code]<tr>
    	<td colspan="2"> <hr /> </td>
    </tr>[/code]
    [code]<?php 
		// close out top-loop
	}[/code]

I forgot to mention the problem…

Everything works independently; however, when I put the nested while statement in, it breaks.

Any help would be greatly appreciated! If you have any questions about the code itself, please let me know and I’ll do my best to explain. I don’t know all of the proper terminology and am still a beginner.

Best,
Trevor

Sponsor our Newsletter | Privacy Policy | Terms of Service