Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Sep 2004
    Location
    Minnesota, USA
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    MySQL Error in class

    Hi, I have a class that returns the category name when given the category ID. It works fine, but I get the following MySQL warning in my logs ...

    Code:
    [client 192.168.0.2] PHP Warning:  mysql_result() [<a href='function.mysql-result'>function.mysql-result</a>]: Unable to jump to row 0 on MySQL result index 64 in /home/vern/public_html/icommerce/etc/class.php on line 38
    The class is:

    PHP Code:
        function checkCat($category_id$url_yes)
        {
            require(
    "config.php");
            
    $query "SELECT * FROM categories WHERE cat_id = $category_id";
            
    $result mysql_query($query$connection);
            
    $cat_name mysql_result($result0"cat_name");
            if (
    $url_yes == 1)
                
    $cat_name '<a href="index-dev.php?cat='.$category_id.'">'.$cat_name.'</a>';
            return 
    $cat_name;
        } 

  • #2
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Well It's a function like the declaration suggests (function checkCat($category_id, $url_yes)) not a class.

  • #3
    New Coder
    Join Date
    Sep 2004
    Location
    Minnesota, USA
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts
    A function in a class.

  • #4
    Senior Coder
    Join Date
    Feb 2003
    Location
    Ontario, Canada
    Posts
    1,223
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The thing about mysql_result () is that you'll get that error when your query doesn't return any rows. That is, mysql_result () needs at least one row to be returned, otherwise it can't grab the field (since your query didn't find anything). You'll get that error when your category ID doesn't exist in the database, but it gets passed to the function anyway.

    To avoid the error, try this:

    PHP Code:
    function checkCat($category_id$url_yes)
    {
      require (
    "config.php");
      
    $query "SELECT cat_name FROM categories WHERE cat_id=$category_id";
      
    $row mysql_fetch_row (mysql_query ($query$connection));
      if (
    $cat_name $row[0])
      {
        if (
    $url_yes == 1)
            
    $cat_name '<a href="index-dev.php?cat='.$category_id.'">'.$cat_name.'</a>';
        return 
    $cat_name;
      }
      else return 
    false;


  • #5
    New Coder
    Join Date
    Sep 2004
    Location
    Minnesota, USA
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts
    AaronW, thanks!

    That fixed my problem and I only needed to tweak it a bit. Thanks for the explanation also. Great help.


  •  

    Posting Permissions

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