-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.php
124 lines (108 loc) · 3.45 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php include ("includes/header.php");
if(isset($_GET['term'])){
$term =urldecode($_GET['term']);
}
else{
$term = "";
}
?>
<div class="searchContainer">
<h4>Search for artist, album or song!</h4>
<input type="text" class="searchInput" value="<?php echo $term; ?>"placeholder="Type Here...." onfocus="this.value = this.value">
</div>
<script>
$(".searchInput").focus();
$(function() {
$(".searchInput").keyup(function(){
clearTimeout(timer);
timer= setTimeout(function(){
var val = $(".searchInput").val();
openPage("search.php?term=" + val);
},2000)
})
})
</script>
<?php if($term == "") exit(); ?>
<div class="trackListContainer borderBottom">
<h2>SONGS</h2>
<ul class="trakList">
<?php
$songsQuery = mysqli_query($con, "SELECT id FROM songs WHERE title LIKE '$term%' LIMIT 10 ");
if(mysqli_num_rows($songsQuery)==0){
echo "<span class='noResults'>No songs found matching " . $term ."</span>";
}
$songIdArray = array();
$i =1;
while($row = mysqli_fetch_array($songsQuery))
{
if($i>15){
break;
}
array_push($songIdArray,$row['id']);
$albumSong = new Song($con,$row['id']);
$albumArtist = $albumSong->getArtist();
echo"<li class='trackListRow'>
<div class='trackCount'>
<img class='play' src='assets/icons/play-white.png' onclick ='setTrack(\"" .$albumSong->getId(). "\",tempPlaylist,true)'>
<span class='trackNumber'>$i</span>
</div>
<div class='trackInfo'>
<span class='trackName'>" .$albumSong->getTitle() . "</span>
<span class='artistName'>" .$albumArtist->getName() ."</span>
</div>
<div class='trackOptions'>
<img class='optionsButton' src='assets/icons/more.png'>
</div>
<div class='trackDuration'>
<span class='duration'>" .$albumSong->getDuration() ."</span>
</div>
</li>";
$i++;
}
?>
<script>
var tempSongIds = '<?php echo json_encode($songIdArray);?>';
tempPlaylist = JSON.parse(tempSongIds);
</script>
</ul>
</div>
<div class="artistContainer borderBottom">
<h2>ARTISTS</h2>
<?php
$artistsQuery = mysqli_query($con,"SELECT id FROM artists WHERE name LIKE '$term%' LIMIT 10");
if(mysqli_num_rows($artistsQuery)==0){
echo "<span class='noResults'>No artists found matching " . $term ."</span>";
}
while($row = mysqli_fetch_array($artistsQuery)){
$artistFound = new Artist($con,$row['id']);
echo "<div class='searchResultRow'>
<div class='artistName'>
<span onclick='openPage(\"artist.php?id=" . $artistFound->getId() . ")'>"
. $artistFound->getName() .
"
</span>
</div>
</div>";
}
?>
</div>
<div class="gridViewContainer">
<h2>ALBUMS</h2>
<?php
$albumQuery = mysqli_query($con, "SELECT * FROM albums WHERE title LIKE '$term%' LIMIT 10 ");
if(mysqli_num_rows($albumQuery)==0){
echo "<span class='noResults'>No albums found matching " . $term ."</span>";
}
while($row = mysqli_fetch_array($albumQuery)){
echo "<div class='gridViewItem'>
<a href='album.php?id=" . $row['id'] . "'>
<img src='".$row['artworkPath']. "'>
<div class'gridViewInfo'>"
. $row['title'] .
"</div>
</a>
</div>";
}
?>
</div>
<?php include ("includes/footer.php"); ?>