I'm getting the above error from my code listed below. The ultimate solution to what I am trying to complete here is being handled under another thread (and most likely with completely different logic behind it). But I wanted to ask about this question so should I ever encounter it I might have a solution for it.

I thought I had this error resolved by adding in the if ($i != $NumParts) section, so ONLY if the $i counter did not equal the number of parts returned then the increment and variable update would be handled. But it still seems to process even when it seems that $i and $NumParts should be equal because it is the last part in the returned results.

Again, it's already been pointed out that this code is not clean because I have logic and display data intermingled, and just avoiding that in the future might prevent this issue from arising. I'd just like to know when my if statement doesn't seem to be processing as I expect it should.

Greg

Here is my current code: (provides exactly what I am looking for in the browser, just has the error displayed)
require("dbconnect.inc");
// Clear/set the ShowPartList variable
$ShowPartList = "";
// Query the database for current list of products
$ProductList = "SELECT tbl_catnav.category_set, tbl_products.part_number ";
$ProductList .= "FROM tbl_products ";
$ProductList .= "LEFT JOIN tbl_catnav ON tbl_products.cat_id = tbl_catnav.lastcatid ";
$ProductList .= "ORDER BY tbl_catnav.category_set, tbl_products.part_number;";
$GetPartList = mysql_query($ProductList);
$NumParts = mysql_num_rows($GetPartList);
$i=0;
$LastCat = "";
$CurrentCat = str_replace(" ", "_",mysql_result($GetPartList,$i,"tbl_catnav.category_set"));
while($i < $NumParts)
{
// Test if active category has changed, if so post new category name
// force it to execute first time through by testing if $i = 0
if ($CurrentCat != $LastCat) {
$ShowPartList .= "<div id=\"CatTitleDiv\">";
$ShowPartList .= "<a href='javascript:unhide(\"" . $CurrentCat . "\");'>" . $CurrentCat . "</a><br />";
$ShowPartList .= "</div> <!-- id=\"CatTitleDiv\" -->";
$ShowPartList .= "<div id=\"" . $CurrentCat . "\" class=\"hidden\">";
}

$ShowPartList .= "<a href=index.php?body=prodshow&prodnum=" . mysql_result($GetPartList,$i,"tbl_products.part_number") . ">" . mysql_result($GetPartList,$i,"tbl_products.part_number") . "</a><br />";
$LastCat = $CurrentCat;
if ($i != $NumParts){
$i++;
$CurrentCat = str_replace(" ", "_",mysql_result($GetPartList,$i,"tbl_catnav.category_set"));
}
if (($CurrentCat != $LastCat) || ($i == $NumParts)) {
// Close current Category Section div
$ShowPartList .= "</div>";
}
}
echo $ShowPartList;