From 2fdf0be3245e89f1aee63cf821cfc186a9b2c36e Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Thu, 11 Feb 2016 17:08:55 +0100 Subject: [PATCH] =?UTF-8?q?order=20by=20dans=20la=20r=C3=A9cup=C3=A9ration?= =?UTF-8?q?=20des=20projets?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/project.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/project.php b/lib/project.php index caaeb3f..cd5ba00 100644 --- a/lib/project.php +++ b/lib/project.php @@ -7,7 +7,7 @@ * @param int $limit Nombre de projets par page * @return array Les projets */ -function getProjects($page = 1, $limit = 5) +function getProjects($page = 1, $limit = 5, $orderBy = 'date', $orderBySens = 'ASC') { if (!is_integer($page)) { throw new InvalidArgumentException('The argument "page" must be an integer.'); @@ -21,7 +21,17 @@ function getProjects($page = 1, $limit = 5) $pdo = getDatabaseConnection(); - $query = $pdo->prepare('select id, title, illustration, description, date from project limit :from, :limit'); + $query = $pdo->prepare( + ' + select + id, title, illustration, description, date + from + project + order by + '.$orderBy.' '.$orderBySens.' + limit + :from, :limit' + ); $query->bindParam(':from', $from, PDO::PARAM_INT); $query->bindParam(':limit', $limit, PDO::PARAM_INT);