I ask for your help because I have been working on an error for 3 days now.
I am trying to create a pagination in php using pdo, but the problem is that I have a Syntax error.
Here is the error:
Warning: PDOStatement::execute(): 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 ”-2′,’2” at line 1 in C:wamp64wwwproject12viewspagination.php on line 21
If someone sees where the error is I will be really grateful.
Thanks in advance.
Voici le code source :
<?php
$limit = 2;
$query = "SELECT count(*) FROM employes";
$s = DB::connect()->query($query);
$total_results = $s->fetchColumn();
$total_pages = ceil($total_results/$limit);
if (!isset($_GET['page'])) {
$page = 1;
} else{
$page = $_GET['page'];
}
$starting_limit = ((int)$page-1)*$limit;
$show = "SELECT * FROM employes ORDER BY id DESC LIMIT ?,?";
$r = DB::connect()->prepare($show);
$r->execute([$starting_limit, $limit]);
while($res = $r->fetch(PDO::FETCH_ASSOC)):
?>
<h4><?php echo $res['id'];?></h4>
<p><?php echo $res['nom'];?></p>
<hr>
<?php
endwhile;
for ($page=1; $page <= $total_pages ; $page++):?>
<a href='<?php echo "?page=$page"; ?>' class="links"><?php echo $page; ?>
</a>
<?php endfor; ?>