0

I have followed like 5 tutorials to make a pagination to my blog and i have failed..

after a lot of research i have this code..

    $limit = 12;
$sql = sprintf("SELECT count(*) FROM posts");
$lista_banco = $pdo->prepare($sql); 
$lista_banco->execute();
$paginas = $lista_banco->fetchColumn();
$total_pages = ceil($paginas/$limit);

if (!isset($_GET['page'])) {
    $page = 1;
} else{
    $page = $_GET['page'];
}
$starting_limit = ($page-1)*$limit;
$show = sprintf("SELECT count(*) FROM posts ORDER BY ID LIMIT ?,?");
$r = $pdo->prepare($show);
$r->execute([$starting_limit, $limit]);

but im getting this error

PHP Fatal error:  Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''0','12'' at line 1 in /home/wil/php estruturado/html/paginacao.php:26
Stack trace:
#0 /home/wil/php estruturado/html/paginacao.php(26): PDOStatement->execute()
#1 {main}
  thrown in /home/wil/php estruturado/html/paginacao.php on line 26

if i change the query final command to ...LIMIT 0, 12") works fine but i need this line owrking

$r->execute([$starting_limit, $limit]);

i have no idea how to solve this problem could anyone help me?

Wilsntn
  • 1
  • 1

0 Answers0