mysqli_num_rows error boolean given

My site use to work fine. But today for some reason pages with mysqli_num_rows takes a very long time to load. I can visit the page but it takes a long time to load. When it loads there are no errors but the error file in the root directory have the following error:

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given

There is no problem with my internet connection because other pages load fast and do not send reports to the error file. This is my first time encountring this problem.
Here is the code for the error line:

function fetch_rows($sql){

    global $con;

    $q = mysqli_query($con, $sql);
    return mysqli_num_rows($q);

}

I have tested the query on PhpMyAdmin and it works fine. But for some reason it takes time to load. I have even checked if the database has a lot of records, but it doesn't I have also emptied it.

Have any of you ran into the same error. Or understands the problem?

Thanks