-
Notifications
You must be signed in to change notification settings - Fork 2
/
serach.php
62 lines (53 loc) · 1.89 KB
/
serach.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');
header("Access-Control-Allow-Headers: X-Requested-With");
header('Content-Type: application/json');
$data = [
"albums"=>[],
"artists"=>[]
];
require 'conn.php';
if(isset($_GET['query']))
{
if(!$conn)
{
$data['error'] = 'There is a problem in our side plz try agian in few momments';
}else{
$id = $_GET['query'];
if(!$result = mysqli_query($conn,"SELECT * FROM albums WHERE title LIKE'%$id%'"))
{
$data['error'] = 'There is a problem in our side plz try agian in few momments';
}else{
if(mysqli_num_rows($result)<1)
{
$data['warning'] = 'Nothing match with your parameters';
}else{
while($row=mysqli_fetch_assoc($result))
{
array_push($data['albums'], [
'id'=>$row['id'],
'title'=>$row['title'],
'artist'=>$row['artist'],
'discription'=>$row['discription'],
'artPath'=>$row['artPath'],
'likes'=>$row['likes'],
]);
}
$sql = mysqli_query($conn,"SELECT * FROM artists WHERE name LIKE '%$id%' ");
while($r=mysqli_fetch_assoc($sql))
{
array_push($data['artists'], [
'id'=>$r['id'],
'name'=>$r['name'],
"img"=>$r['imageUrl']
]);
}
}
}
}
}else{
$data['error'] = 'You must provide album id to fetch album data. Is it not abvious?';
}
echo json_encode($data);
?>