order by dans la récupération des projets

This commit is contained in:
Simon Vieille 2016-02-11 17:08:55 +01:00
parent de10cce572
commit 2fdf0be324
1 changed files with 12 additions and 2 deletions

View File

@ -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);