-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch_result_xml.php
110 lines (85 loc) · 3.19 KB
/
search_result_xml.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
<?php
include("connect.php");
include("login_functions.php");
header("Content-type:text/xml;charset=utf-8");
echo '<?xml version="1.0"?>';
if(loggedin()){
echo '<?xml-stylesheet type="text/xsl" href="loggedin/search_result_loggedin.xsl"?>';
$username = $_SESSION['username'];
echo "<searchcontent>";
echo "<sessionuser>$username</sessionuser>";
}
else{
echo '<?xml-stylesheet type="text/xsl" href="search_result.xsl"?>';
echo "<searchcontent>";
}
$search = $_GET['search'];
$type = $_GET['search_type'];
$XMLcontent = "";
if(isset($search)&&isset($type)){
if($type == "song"){
$query = "SELECT Artist, Title, Id FROM tutorial WHERE Title='$search'";
$result = mysql_query($query) or die("Query failed.");
while ($row = mysql_fetch_object($result)){
$id = $row->Id;
$artist = $row->Artist;
$title = $row->Title;
$XMLcontent = $XMLcontent . "<tutorial>";
$XMLcontent = $XMLcontent . "<id>$id</id>";
$XMLcontent = $XMLcontent . "<artist><![CDATA[$artist]]></artist>";
$XMLcontent = $XMLcontent . "<title><![CDATA[$title]]></title>";
$XMLcontent = $XMLcontent . "</tutorial>";
}
echo utf8_encode($XMLcontent);
echo "</searchcontent>";
}
else if($type == "artist"){
$query = "SELECT Artist, Title, Id FROM tutorial WHERE Artist='$search'";
$result = mysql_query($query) or die("Query failed.");
while ($row = mysql_fetch_object($result)){
$id = $row->Id;
$artist = $row->Artist;
$title = $row->Title;
$XMLcontent = $XMLcontent . "<tutorial>";
$XMLcontent = $XMLcontent . "<id>$id</id>";
$XMLcontent = $XMLcontent . "<artist><![CDATA[$artist]]></artist>";
$XMLcontent = $XMLcontent . "<title><![CDATA[$title]]></title>";
$XMLcontent = $XMLcontent . "</tutorial>";
}
echo utf8_encode($XMLcontent);
echo "</searchcontent>";
}
else if($type == "genre"){
$query = "SELECT Artist, Title, Id FROM tutorial WHERE Genre='$search'";
$result = mysql_query($query) or die("Query failed.");
while ($row = mysql_fetch_object($result)){
$id = $row->Id;
$artist = $row->Artist;
$title = $row->Title;
$XMLcontent = $XMLcontent . "<tutorial>";
$XMLcontent = $XMLcontent . "<id>$id</id>";
$XMLcontent = $XMLcontent . "<artist><![CDATA[$artist]]></artist>";
$XMLcontent = $XMLcontent . "<title><![CDATA[$title]]></title>";
$XMLcontent = $XMLcontent . "</tutorial>";
}
echo utf8_encode($XMLcontent);
echo "</searchcontent>";
}
else{
$query = "SELECT Artist, Title, Id FROM tutorial WHERE Username='$search'";
$result = mysql_query($query) or die("Query failed.");
while ($row = mysql_fetch_object($result)){
$id = $row->Id;
$artist = $row->Artist;
$title = $row->Title;
$XMLcontent = $XMLcontent . "<tutorial>";
$XMLcontent = $XMLcontent . "<id>$id</id>";
$XMLcontent = $XMLcontent . "<artist><![CDATA[$artist]]></artist>";
$XMLcontent = $XMLcontent . "<title><![CDATA[$title]]></title>";
$XMLcontent = $XMLcontent . "</tutorial>";
}
echo utf8_encode($XMLcontent);
echo "</searchcontent>";
}
}
?>