diff --git a/BancaDati/BancaDati.php b/BancaDati/BancaDati.php index 7dc16f4..9690979 100644 --- a/BancaDati/BancaDati.php +++ b/BancaDati/BancaDati.php @@ -102,27 +102,30 @@ class BancaDati { /** * einheitliche Select Funktion + * kann sortiert werden durch ["by"]=>"col" und ["order"]=>"ASC|DESC" * @param string $table * @param array $where ["column"]=>"value" es wird mit LIKE verglichen und mit AND verbunden - * @param array|null $order ["by"]=>"column"; ["order"]=>"ASC|DESC" * @return void * @author Malte Schulze Hobeling */ - public function select(string $table, array $where, array $order = null){ + public function select(string $table, array $where){ $whereString = ""; + $orderString = ""; + if(isset($where["by"])){ + $orderString = " ORDER BY " . $where["by"]; + unset($where["by"]); + if(isset($where["order"])){ + $orderString .= " " . $where["order"]; + unset($where["order"]); + } + } foreach ($where as $col => $v) { if($whereString != ""){ $whereString .= " AND "; } $whereString .= "`" . $col . "` LIKE '" . $v . "'"; } - $sql = "SELECT * FROM ".$table." WHERE ".$whereString.";"; - if(isset($order["by"])){ - $sql .= " ORDER BY ".$order["by"]; - } - if(isset($order["order"])){ - $sql .= $order["order"]; - } + $sql = "SELECT * FROM ".$table." WHERE ".$whereString.$orderString.";"; try { return $this->pdo->query($sql)->fetch(); }catch (PDOException $e){