Hi, I'm doing a page through php but I have a problem when I want to count the number of records and I can not use it to get the number of pages.
Php code:
<?php
require_once 'database.php';
$database_connection = database_connect();
$title='hola';
$content='<div>';
//user input
$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
$perPage = isset($_GET['per-page']) && $_GET['per-page'] <= 50 ? (int)$_GET['per-page'] : 5;
//Positioning
$start = ($page > 1) ? ($page * $perPage) - $perPage : 0;
$art = $database_connection->query("SELECT id FROM coffee");
//Query
$articles = $database_connection->prepare("SELECT id FROM coffee LIMIT {$start},{$perPage}");
$articles->execute();
$articles = $articles->fetchAll();
$total = $database_connection->query("SELECT COUNT(*) FROM coffee");
//pages
$pages = ($total/$perPage);
$content .= '<div>';
include 'Template_1.php';
?>
Basically my question is here $pages = ($total/$perPage);
how could the conversion be so that when I do the query:
$total = $database_connection->query("SELECT COUNT(*) FROM coffee");
is an integer and not a resultset.