Add ordering reads in dblayer

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1222 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2014-03-17 15:16:14 +00:00
parent 5dbf9bcfcc
commit a11b4d0bb7

View File

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