count number of rows in table using php

前端 未结 6 650
一生所求
一生所求 2020-12-20 00:00

I just want to count the number of rows in a table that already created in a database using php. I used mysqli(). I need the number of rows in the table as the output.

6条回答
  •  佛祖请我去吃肉
    2020-12-20 00:23

     query("SELECT count(*) cc FROM tablename")) {
    
         /* fetch the first row as result */
         $row = $result->fetch_assoc();
    
        printf("Result set has %d rows.\n", $row['cc']);
    
       /* close result set */
        $result->close();
     }
    
     /* close connection */
     $mysqli->close();
    ?>
    

    In fact it's a common question you can find the answer anywhere.

    Like, http://php.net/manual/en/mysqli-result.num-rows.php

    You could separate this problem in to two

    1. I wanna know how to connect to mysql.
    2. I wanna know how to write that sql instruction.

提交回复
热议问题