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 3 of 3
  1. #1
    New Coder
    Join Date
    Nov 2013
    Posts
    12
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Query Help "mysqli_num_rows() expects parameter 1"

    Hello all,

    I'm getting the classic:

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

    I've tried every alteration of the query i can think of but I'm still getting the same result. I figured I could use another set of eyes.

    Here is the offending code:

    PHP Code:
    $sql "SELECT s.*, u.avatar
            FROM satus AS s
            LEFT JOIN users AS u ON u.username = s.account_name
            WHERE s.type='a' OR s.type='c'
            ORDER BY s.postdate DESC LIMIT 20"
    ;
            
    $query_account mysqli_query($db_conx$sql);
            
    $accountnumrows mysqli_num_rows($query_account);
            if(
    $accountnumrows 0){
                while (
    $row mysqli_fetch_array($query_accountMYSQLI_ASSOC)) {
            
    $avatar_an $row["avatar"];
            } 
    I'm sure there is something blatantly wrong but I just can't seem to see it.

    Any help you could give would be greatly appreciated!

    Thanks so much!!!

  • #2
    Regular Coder
    Join Date
    Sep 2002
    Posts
    454
    Thanks
    0
    Thanked 20 Times in 20 Posts
    It usually means there's something off in your query string, so the query returns an error causing num_row() to fail.

    test with:
    if(!mysqli_query($db_conx, $sql)){
    echo mysqli_error();
    }

    I'm only guessing at the error function looks like mysql...
    NO Limits!! DHCreationStation.com
    ------------------------------------------------------------
    Broken items wanted for tinkerin'! PostItNow@BrokenEquipment.com
    Global Complaint Dept.

  • #3
    Regular Coder Redcoder's Avatar
    Join Date
    May 2012
    Location
    /dev/null
    Posts
    333
    Thanks
    2
    Thanked 47 Times in 46 Posts
    The problem is your query returned false meaning there is something wrong with $sql.

    Try to echo the error by doing this:

    PHP Code:
    $sql "SELECT s.*, u.avatar 
            FROM satus AS s 
            LEFT JOIN users AS u ON u.username = s.account_name 
            WHERE s.type='a' OR s.type='c' 
            ORDER BY s.postdate DESC LIMIT 20"

           
    //Echo the error
            
    $query_account mysqli_query($db_conx$sql) or die(mysqli_error($db_conx); 
            
    $accountnumrows mysqli_num_rows($query_account); 
            if(
    $accountnumrows 0){ 
                while (
    $row mysqli_fetch_array($query_accountMYSQLI_ASSOC)) { 
            
    $avatar_an $row["avatar"]; 
            } 


  •  

    Tags for this Thread

    Posting Permissions

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