mirror of
				https://github.com/pierre42100/ComunicAPI
				synced 2025-10-31 10:14:51 +00:00 
			
		
		
		
	Created search user method
This commit is contained in:
		| @@ -332,9 +332,7 @@ class DBLibrary { | |||||||
|             if(count($fieldsList) == 0) |             if(count($fieldsList) == 0) | ||||||
|                 $fields = "*"; |                 $fields = "*"; | ||||||
|             else { |             else { | ||||||
|                 $fields = ""; |                 $fields = implode(", ", $fieldsList); | ||||||
|                 foreach($fieldsList as $processField) |  | ||||||
|                     $fields .= $processField.", "; |  | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             //Generating SQL |             //Generating SQL | ||||||
|   | |||||||
| @@ -14,8 +14,28 @@ class searchUser { | |||||||
| 	 * @param Integer $limit The number of results to return on the screen | 	 * @param Integer $limit The number of results to return on the screen | ||||||
| 	 * @return Array the result of the result | 	 * @return Array the result of the result | ||||||
| 	 */ | 	 */ | ||||||
| 	public function search($query, $limit){ | 	public function search($query, $limit) : array{ | ||||||
| 		return array(1, 2); |  | ||||||
|  | 		//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; | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -36,3 +36,10 @@ $config->set("mysql", array( | |||||||
|     "user" => "root",  |     "user" => "root",  | ||||||
|     "password" => "root" |     "password" => "root" | ||||||
| )); | )); | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * Tables of database prefix | ||||||
|  |  * | ||||||
|  |  * For new tables only | ||||||
|  |  */ | ||||||
|  | $config->set("dbprefix", "comunic_"); | ||||||
							
								
								
									
										1
									
								
								init.php
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								init.php
									
									
									
									
									
								
							| @@ -43,6 +43,7 @@ $db->openMYSQL($cs->config->get('mysql')['host'], | |||||||
|         $cs->config->get('mysql')['user'],  |         $cs->config->get('mysql')['user'],  | ||||||
|         $cs->config->get('mysql')['password'],  |         $cs->config->get('mysql')['password'],  | ||||||
|         $cs->config->get('mysql')['database']); |         $cs->config->get('mysql')['database']); | ||||||
|  | define("DBprefix", $cs->config->get("dbprefix")); | ||||||
| unset($db); | unset($db); | ||||||
|  |  | ||||||
| //Add token object | //Add token object | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Pierre
					Pierre