count number of rows in table using php

前端 未结 6 621
一生所求
一生所求 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:30

     query("SELECT columnName from tablename")) {
    
        /* determine number of rows result set */
         $row_cnt = $result->num_rows;
    
        printf("Result set has %d rows.\n", $row_cnt);
    
       /* close result set */
        $result->close();
     }
    
     /* close connection */
     $mysqli->close();
    ?>
    

    EDIT:

    $result = $db->query("SELECT COUNT(*) FROM `table`");
    $row = $result->fetch_row();
    echo '#: ', $row[0];
    

提交回复
热议问题