how to get the total row count with mysqli

前端 未结 3 710
轮回少年
轮回少年 2020-12-10 17:14

i am trying to understand mysqli extension and did google but got very few info on this except php.net which was helpful.

now after all this i am trying to achieve

3条回答
  •  失恋的感觉
    2020-12-10 17:43

    You may try this:

    //Establish connection using mysqli api
    $conn = mysqli_connect('hostname', 'username', 'password', 'database_name');
    
    $sql = "SELECT SQL_CALC_FOUND_ROWS *, post.id as pid, bla bla FROM account ORDER BY pid ASC". $eb["array"]['querylimit'];
    
    $sql2 = "SELECT FOUND_ROWS()";
    
    $result1 = $conn->query($sql);
    $result2 = $conn->query($sql2);
    $TotalRcount = $result2->fetch_row();
    
    // Performing record count [current]
    // $RecordCount = $result->num_rows();
    
    while($row = $result->fetch_array(MYSQLI_BOTH)){
        // read columns
    }
    

    In a while loop i have used MYSQLI_BOTH constant but you may change it to MYSQLI_NUM or MYSQLI_ASSOC whichever you need.

提交回复
热议问题