This commit is contained in:
Malte Schulze Hobeling 2023-01-12 14:05:19 +01:00
parent e31b7b6319
commit 151b1ab549

View File

@ -100,16 +100,23 @@ class BancaDati {
} }
} }
/**
public function select(string $table, array $data, array $order = null){ * einheitliche Select Funktion
$where = ""; * @param string $table
foreach ($data as $col => $v) { * @param array $where ["column"]=>"value" es wird mit LIKE verglichen und mit AND verbunden
if($where != ""){ * @param array|null $order ["by"]=>"column"; ["order"]=>"ASC|DESC"
$where .= " AND "; * @return void
* @author Malte Schulze Hobeling
*/
public function select(string $table, array $where, array $order = null){
$whereString = "";
foreach ($where as $col => $v) {
if($whereString != ""){
$whereString .= " AND ";
} }
$where .= $col . "=" . $v; $whereString .= $col . " LIKE " . $v;
} }
$sql = "SELECT * FROM ".$table." WHERE ".$where; $sql = "SELECT * FROM ".$table." WHERE ".$whereString;
if(isset($order["by"])){ if(isset($order["by"])){
$sql .= " ORDER BY ".$order["by"]; $sql .= " ORDER BY ".$order["by"];
} }