Can't return correct row count from database using php pdo

前端 未结 2 1238
庸人自扰
庸人自扰 2021-01-28 19:16

I am trying to return the row count from a table in my database but continue to get the wrong value. I need the row count to process subset values for pagination. There are 11 i

2条回答
  •  萌比男神i
    2021-01-28 19:57

    you should replace

    $rowCount = $query->rowCount();
    

    with

    $rowCount = $query->fetchColumn();
    

    also, take a look at FOUND_ROWS()

    there is no sense in calling fetch_num_rows 2 times, it is enough to do:

    $numArticles = $rowCount = $article->fetch_num_rows();
    

提交回复
热议问题