SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot GHicks's Avatar
    Join Date
    Oct 2003
    Location
    Prescott Valley, Arizona, United States
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [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.

    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;

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Do an echo of $i

  3. #3
    SitePoint Zealot GHicks's Avatar
    Join Date
    Oct 2003
    Location
    Prescott Valley, Arizona, United States
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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!

    Greg


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •