diff --git a/dblayer.php b/dblayer.php index 72d6084..7b0ffce 100644 --- a/dblayer.php +++ b/dblayer.php @@ -106,8 +106,10 @@ class dblayer extends PDO operator and the associated select value $select = array (array ($key, $val, $operator)) $key=>column, $val=>value to found, $operator=>'LIKE', =... + $order = array (array ($key, $orientation)) + $key=>column, $orientation=ASC/DESC */ - function read ($select=null) + function read ($select=null, $order=null) { if ($this->db === null) throw new Exception ("Database not connected"); @@ -127,6 +129,21 @@ class dblayer extends PDO } } + if ($order !== null) + { + $req .= " ORDER BY "; + foreach ($order as $n=>$o) + { + if ($n > 0) + $req .= ","; + $req .= $o[0]; + if (isset ($o[1]) && $o[1] === "DESC") + $req .= " DESC"; + else + $req .= " ASC"; + } + } + if ($this->debug) echo "DEBUG : $req\n"; $st = $this->db->prepare ($req); if ($select !== NULL)