-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_search_results.php
More file actions
50 lines (45 loc) · 1.7 KB
/
get_search_results.php
File metadata and controls
50 lines (45 loc) · 1.7 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
<?php
extract($_GET);
//echo "search=".$search;
//SELECT * FROM `video` WHERE `video_name` LIKE '%Piano%' OR `details` LIKE '%Piano%' OR `channel` LIKE '%Piano%' OR `category` LIKE '%Piano%' ORDER BY `likes` DESC
header("Content-type:application/json");
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "video_library";
/*$servername = "0.0.0.0:3306";
$username = "root";
$password = "yash";
$dbname = "TEST";*/
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM `video` WHERE `video_name` LIKE '%".$search."%' OR `details` LIKE '%".$search."%' OR `channel` LIKE '%".$search."%' OR `category` LIKE '%".$search."%' ORDER BY `likes` DESC";
$result = $conn->query($sql);
$response_json = array();
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$temp_res = array();
$temp_res['video_name'] = $row['video_name'];
$temp_res['thumb_img'] = $row['id'];
$temp_res['duration'] = $row['duration'];
$temp_res['details'] = $row['details'];
$temp_res['channel'] = $row['channel'];
$temp_res['rating'] = $row['rating'];
$temp_res['views'] = $row['views'];
$temp_res['id'] = $row['id'];
$temp_res['likes'] = $row['likes'];
$temp_res['user_id'] = $row['user_id'];
array_push($response_json, $temp_res);
}
} else {
echo "0 results";
}
//echo count($response_json);
$conn->close();
echo json_encode($response_json);
?>