Php 无法创建ceil阵列
我正试图用这个做一个分页页面,但不断出现错误 这是我的密码:Php 无法创建ceil阵列,php,mysql,pagination,Php,Mysql,Pagination,我正试图用这个做一个分页页面,但不断出现错误 这是我的密码: <?php include "common.php"; ?> <?php $query = "SELECT COUNT(id) FROM actiongame"; try { // These two statements run the query against your database table. $stmt = $db->prepare
<?php include "common.php"; ?>
<?php
$query = "SELECT COUNT(id) FROM actiongame";
try
{
// These two statements run the query against your database table.
$stmt = $db->prepare($query);
$stmt->execute();
}
catch(PDOException $ex)
{
// Note: On a production website, you should not output $ex->getMessage().
// It may provide an attacker with helpful information about your code.
die("Failed to run query: " . $ex->getMessage());
}
$rows = $stmt->fetchAll();
foreach($rows as $row):
$total_records = $row;print_r($total_records);
//just to see what is the $total_records
// i get this reult with print_r : Array ( [COUNT(id)] => 2969 )
$total_pages = ceil($total_records / 48);
//but i get fatal error = =
//Fatal error: Unsupported operand types in C:\wamp\www\category.php on line
print_r($total_pages);
endforeach;
unset($row);
?>
如果您试图接收一个数组,则可以在数值上执行此操作 尝试按如下方式编辑查询:
$query = "SELECT COUNT(id) AS tot FROM actiongame";
$total_records = $row['tot'];
然后您的PHP代码如下所示:
$query = "SELECT COUNT(id) AS tot FROM actiongame";
$total_records = $row['tot'];
谢谢,它可以工作,7分钟后将设置为接受答案