-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.php
38 lines (32 loc) · 1.42 KB
/
search.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
require_once('./app/autoload.php');
if (isset($_GET['q'])) {
$pdo = new PDO('mysql:host=127.0.0.1;dbname=yt-social;charset=utf8mb4', 'root', '', array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8mb4'"));
$query = $_GET['q'];
$querye = explode(" ", $query);
$x = 0;
$construct = "";
$params = array();
foreach ($querye as $term) {
$x++;
if ($x == 1) {
$construct .= "user_full_name LIKE CONCAT('%',:search$x,'%') OR user_firstname LIKE CONCAT('%',:search$x,'%') OR user_lastname LIKE CONCAT('%',:search$x,'%') OR user_email LIKE CONCAT('%',:search$x,'%')";
}else {
$construct .= " AND user_full_name LIKE CONCAT('%',:search$x,'%') OR user_firstname LIKE CONCAT('%',:search$x,'%') OR user_lastname LIKE CONCAT('%',:search$x,'%') OR user_email LIKE CONCAT('%',:search$x,'%')";
}
$params["search$x"] = $term;
}
$results = $pdo->prepare("SELECT * FROM users WHERE $construct");
$results->execute($params);
// if ($results->rowCount() == 0) {
// echo "0 results found <hr>";
// }else {
// echo $results->rowCount() . " results found <br>";
// }
// foreach ($results->fetchAll() as $result) {
// echo "<a href='profile/" . $result['user_user_id'] . "'>" . $result['user_full_name'] . "</a><br>";
// }
}else {
header("Location: index.php");
exit();
}