-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathsearch.php
More file actions
53 lines (51 loc) · 1.92 KB
/
search.php
File metadata and controls
53 lines (51 loc) · 1.92 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
//load database connection
//echo "hello";
$host = "localhost";
$user = "root";
$password = "cloudera";
$database_name = "hackathon";
$pdo = new PDO("mysql:host=$host;dbname=$database_name", $user, $password, array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
));
// Search from MySQL database table
// echo "hello again";
$search=$_POST['search'];
echo $search."</br>";
$search = trim($search);
$search_explode = explode(" ", $search);
$cons = "select * from scheme where ";
$count = 0;
foreach ($search_explode as $exploded_search ) {
# code...
$count++;
if( $count == 1){
$cons .= "name LIKE '%$exploded_search%' OR kewwords LIKE '%$exploded_search%' ";
} else{
$cons .= "OR name LIKE '%$exploded_search%' OR kewwords LIKE '%$exploded_search%' ";
}
}
$cons .= " LIMIT 0, 10";
echo $cons."</br>";
$query = $pdo->prepare($cons);
//select * from scheme where name LIKE '%$search%' OR kewwords LIKE '%$search%' LIMIT 0 , 10
$query->bindValue(1, "%$search%-", PDO::PARAM_STR);
$query->execute();
// echo "again hello";
// Display search result
if (!$query->rowCount() == 0) {
echo "Search found :<br/>";
echo "<table style=\"font-family:arial;color:#333333;\">";
echo "<tr><td style=\"border-style:solid;border-width:1px;border-color:#98bf21;background:#98bf21;\">Title Scheme</td><td style=\"border-style:solid;border-width:1px;border-color:#98bf21;background:#98bf21;\">Descri[tion</td></tr>";
while ($results = $query->fetch()) {
echo "<tr><td style=\"border-style:solid;border-width:1px;border-color:#98bf21;\">";
echo $results['name'];
echo "</td><td style=\"border-style:solid;border-width:1px;border-color:#98bf21;\">";
echo $results['kewwords'];
echo "</td>";
}
echo "</table>";
} else {
echo 'Nothing found';
}
?>