Je souhaite créer une fonction qui gère les clauses ORDER BY et LIMIT. J'ai donc fait ceci :
En dehors de $identifiant_selection, les autres arguments semblent pas être pris en compte par la fonction.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 function getSelection($identifiant_selection, $rang = true, $rand = false, $limit = false) { global $db; $orderby = ''; if($rang == false and $rand == false) $orderby .= 'si.rang_item'; if($rang == true and $rand == false) $orderby .= 'si.rang_item'; if($rang == false and $rand == true) $orderby .= 'rand()'; if($rang == true and $rand == true) $orderby .= 'rand(), si.rang_item'; $sql = 'SELECT si.url_item as url, si.rang_item as rang FROM selections_items si INNER JOIN selections s ON s.id_selection = si.selection_id WHERE s.identifiant_selection = :identifiant_selection '; $sql .= 'ORDER BY '.$orderby; if($limit != false) $sql .= ' LIMIT '.$limit; $statement = $db->prepare($sql); $statement->execute(array(':identifiant_selection' => $identifiant_selection)); return $statement->fetchAll(); } //ceci marche getSelection(2); //ceci ne marche pas getSelection(2, $limit = 20);
Merci d'avance pour votre aide.
Meilleures salutations.
Partager