Téléverser les fichiers vers "sql"
This commit is contained in:
parent
48c6cf4022
commit
30dd67df75
26
sql/sql_utils.php
Normal file
26
sql/sql_utils.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
function get_books($page = 1, $resultsPerPage = 10){
|
||||
global $pdo;
|
||||
|
||||
$page = max(1, (int)$page);
|
||||
$offset = ($page - 1) * $resultsPerPage;
|
||||
|
||||
$count_query = 'SELECT COUNT(*) FROM Livres AS L INNER JOIN Auteurs AS A ON L.auteur_id = A.auteur_id';
|
||||
$count = $pdo->query($count_query)->fetchColumn();
|
||||
$total_pages = ceil($count / $resultsPerPage);
|
||||
|
||||
$statement = $pdo->prepare('SELECT L.titre, L.annee_publication, A.nom, A.prenom
|
||||
FROM Livres AS L
|
||||
INNER JOIN Auteurs AS A ON L.auteur_id = A.auteur_id
|
||||
LIMIT :limit OFFSET :offset');
|
||||
$statement->bindValue(':limit', $resultsPerPage, PDO::PARAM_INT);
|
||||
$statement->bindValue(':offset', $offset, PDO::PARAM_INT);
|
||||
$statement->execute();
|
||||
return [
|
||||
'books' => $statement->fetchAll(PDO::FETCH_ASSOC),
|
||||
'current_page' => $page,
|
||||
'total_pages' => $total_pages,
|
||||
'total_results' => $count
|
||||
];
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user