這個代碼以前是在
mysql中,現在因為它已被棄用,我決定在mysqli中轉換我的代碼,但是我在我的頁面中有這個問題有分頁,在它使用mysql之前沒有錯誤,但現在我得到了這一行出錯:
Warning: mysqli_fetch_assoc() expects exactly 1 parameter, 2 given
錯誤是顯而易見的,我知道,但我不知道如何以另一種方式做到這一點,因為以前我的代碼在那一行是
$pages = ceil(mysql_result($pages_query, 0) / $limit); // total number of pages
我也嘗試過這個
$pages = ceil($pages_query / $limit); // total number of pages
但是我得到了這個錯誤
Notice: Object of class mysqli_result could not be converted to int
所以我想知道如何將mysql_ * mysql_result轉換為mysqli?或者還有其他方法嗎?
到目前為止我的代碼是這樣的:
include 'dbcontroller.php';
$limit = 10; // limit the number of post per page
$pages_query = mysqli_query($conn, "SELECT COUNT('id') FROM news");
$pages = ceil($pages_query / $limit); // total number of pages
$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
$start = ($page - 1) * $limit; // set the page to 0
$query = mysqli_query($conn, "SELECT * FROM news ORDER BY date DESC LIMIT $start, $limit");
while($row = mysqli_fetch_array($query)) {
....
}
?>