Search code examples
phpmysqlimysql-num-rows

Num Rows always ='s 1 for some reason. QUICK FIX


I don't know if i am doing it right, this is what I got:

while($row = mysqli_fetch_assoc($result)) {
     $items = mysqli_num_rows($row); 
}

It always sets $items = to 1 for some reason.

Here is my mysqli_query...

$top10_query = "SELECT * FROM users WHERE userid='$userid'";
                        $result = mysqli_query($cxn, $top10_query) or die("Couldn't execute query.");
                        $row = mysqli_fetch_assoc($result);

Solution

  • Well, $row only contains one row so....

    $items = mysqli_num_rows($result)
    

    should give you the correct number of items


    Anyway, why are you doing that in a loop? The number of rows is constant...