diff --git a/classes/DBLibrary.php b/classes/DBLibrary.php index ac86f6d..a0ea86a 100755 --- a/classes/DBLibrary.php +++ b/classes/DBLibrary.php @@ -332,9 +332,7 @@ class DBLibrary { if(count($fieldsList) == 0) $fields = "*"; else { - $fields = ""; - foreach($fieldsList as $processField) - $fields .= $processField.", "; + $fields = implode(", ", $fieldsList); } //Generating SQL diff --git a/classes/components/searchUser.php b/classes/components/searchUser.php index 02fa18c..e5677db 100644 --- a/classes/components/searchUser.php +++ b/classes/components/searchUser.php @@ -14,8 +14,28 @@ class searchUser { * @param Integer $limit The number of results to return on the screen * @return Array the result of the result */ - public function search($query, $limit){ - return array(1, 2); + public function search($query, $limit) : array{ + + //Prepare query string + $query = "%".str_replace(" ", "%", $query)."%"; + + //Prepare a request on the database + $tableName = "utilisateurs"; + $conditions = "WHERE (nom LIKE ?) || (prenom LIKE ?) || (CONCAT(prenom, '%', nom) LIKE ?) || (CONCAT(nom, '%', prenom) LIKE ?) LIMIT ".$limit*1; + $datasCond = array($query, $query, $query, $query); + $fields = array("ID"); + + //Perform the request on the database + $results = CS::get()->db->select($tableName, $conditions, $datasCond, $fields); + + //Prepare return + $return = array(); + foreach($results as $value){ + $return[] = $value["ID"]; + } + + //Return result + return $return; } } diff --git a/config/main.php b/config/main.php index 8ebb75f..a19b590 100644 --- a/config/main.php +++ b/config/main.php @@ -36,3 +36,10 @@ $config->set("mysql", array( "user" => "root", "password" => "root" )); + +/** + * Tables of database prefix + * + * For new tables only + */ +$config->set("dbprefix", "comunic_"); \ No newline at end of file diff --git a/init.php b/init.php index f21ec1a..12f5c2b 100644 --- a/init.php +++ b/init.php @@ -43,6 +43,7 @@ $db->openMYSQL($cs->config->get('mysql')['host'], $cs->config->get('mysql')['user'], $cs->config->get('mysql')['password'], $cs->config->get('mysql')['database']); +define("DBprefix", $cs->config->get("dbprefix")); unset($db); //Add token object