我正在进行分页,我得到此错误是我第一次使用此错误,感谢您的帮助,谢谢!
致命错误:在第47行的C:\ xampp \ htdocs \ pritcluster \ register_companies.php中的非对象上调用成员函数bindParam()
include_once 'config/database.php';
try {
// Find out how many items are in the table
$total = $con -> query('SELECT company_name, email, tel, website
FROM company') -> fetch_assoc();
// How many items to list per page
$limit = 10;
// How many pages will there be
$pages = mysqli_fetch_array($total, $limit);
// What page are we currently on?
$page = min($pages, filter_input(INPUT_GET, 'page', FILTER_VALIDATE_INT, array (
'option' => array(
'default' => 1,
'min_range' => 1,
),
)));
// Calculate the offset for the query
$offset = ($page - 1) * $limit;
// Some information to display to the user
$start = $offset + 1;
$end = min(($offset + $limit), $total);
// The "back" link
$prevlink = ($page > 1) ? '<a herf="?page=1" title = "First page"> «</a>
<a href="?page=' . ($page - 1) . '" title="Previous page">‹</a>' : '<span
class="disabled">«</span> <span class="disabled">‹</span>';
// The "forward" link
$nextlink = ($page < $pages) ? '<a href="?page=' . ($page + 1) . '" title="Next
page">›</a> <a href="?page=' . $pages . '" title="Last page">»</a>' :
'<span class="disabled">›</span> <span class="disabled">»</span>';
// Prepare the paged query
$stmt = $con->prepare('
SELECT
company_name, email, tel, website
FROM
company
ORDER BY
ASC
LIMIT
:limit
OFFSET
:offset
');
// Bind the query params
$stmt->bindParam(':limit', $limit, PDO:: PARAM_INT);
$stmt->bindParam(':offset', $offset, PDO:: PARAM_INT);
$stmt->execute();
答案 0 :(得分:1)
我认为查询错误。
SELECT
company_name, email, tel, website
FROM
company
ORDER BY
ASC
LIMIT
:limit
OFFSET
:offset
您没有按顺序使用任何列。请在phpmyadmin(或在控制台中)运行此查询并检查。