mySQL function problem

Discussion in 'PHP' started by GSto, May 18, 2008.

  1. #1
    I wrote this function to get the number of rows in the table for each particular category. I wrote this function, it won't work, and I can't figure out why.

    function getNumRows($category){
    $query = "SELECT * FROM direc WHERE category=\"$category\"";
    $result = mysqli_query($cxn,$query);
    if($result){
    echo 'query successful';
    }
    else{
    echo 'query failed';
    }
    $num = mysqli_num_rows($result);
    return $num;
    }

    I know that $cxn works, so the problem must be with the $query. but I tried the syntax on the mySQL command line and it worked, so what gives here? what is wrong with this function?
     
    GSto, May 18, 2008 IP
  2. GSto

    GSto Peon

    Messages:
    218
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    nevermind, I figured it out. I had to add the $cxn as an argument to the function.
     
    GSto, May 18, 2008 IP