[function.mysql-result]: Unable to jump to row ##

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.


Here is my current code: (provides exactly what I am looking for in the browser, just has the error displayed)
// 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);
$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 .= "&lt;a href=index.php?body=prodshow&prodnum=" . mysql_result($GetPartList,$i,"tbl_products.part_number") . "&gt;" . mysql_result($GetPartList,$i,"tbl_products.part_number") . "&lt;/a&gt;&lt;br /&gt;";
    $LastCat = $CurrentCat;
    if ($i != $NumParts){
      $CurrentCat = str_replace(" ", "_",mysql_result($GetPartList,$i,"tbl_catnav.category_set"));
    if (($CurrentCat != $LastCat) || ($i == $NumParts)) {
      // Close current Category Section div
      $ShowPartList .= "&lt;/div&gt;";
  echo $ShowPartList;

Do an echo of $i

Figured it out, I needed to pull my command to increment the i value OUT of the test. That way in increments it up, THEN tests. Otherwise it was testing, was still less than the $NumParts value so it incremented, then tried to assign a new value off that incremented number (which was too large). Now it increments, THEN tests so when it actually totals the number of parts it stops.

Just needed to rest a bit I guess to figure it out!