-
Notifications
You must be signed in to change notification settings - Fork 2
/
database.php
127 lines (106 loc) · 4.59 KB
/
database.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
125
126
127
<!DOCTYPE html>
<html lang="en">
<head>
<?php
include("res/php/auth.php");
include("res/php/loadfunc.php");
include("res/php/links.php");
?>
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container-fluid">
<a class="brand" href="./index.php">JamWalkr</a>
<ul class="nav">
<li><a href="./index.php"><i class="icon-home icon-white"></i></a></li>
<li><a href="./lfm.php"><i class="icon-music icon-white"></i></a></li>
<li><a href="./8tracks.php"><i class="icon-headphones icon-white"></i></a></li>
<li><a href="./map.php"><i class="icon-map-marker icon-white"></i></a></li>
<li class="active"><a href="./database.php"><i class="icon-hdd icon-white"></i></a></li>
</ul>
</div>
</div>
</div>
<div class="container-fluid" style="margin-top: 50px;">
<div class="row-fluid">
<div class="span3 visible-desktop">
<ul class="nav nav-pills nav-stacked">
<li><a href="./index.php"><i class="icon-home"></i> Home</a></li>
<li><a href="./lfm.php"><i class="icon-music"></i> Last.fm API</a></li>
<li><a href="./8tracks.php"><i class="icon-headphones"></i> 8Tracks API</a></li>
<li><a href="./map.php"><i class="icon-map-marker"></i> Google Maps API</a></li>
<li class="active"><a href="./database.php"><i class="icon-hdd"></i> MySQL Database</a></li>
</ul>
</div>
<div class="span9">
<h1>MySQL Database</h1>
<!-- CHANGE USERNAME AND PASSWORD FOR NOW FOR USE -->
<?php
$mysql_host = "mysql13.000webhost.com";
$username="a9185905_smucker";
$password="ProfessorWhite3308";
$database="a9185905_jar";
?>
<?php
mysql_connect($mysql_host,$username,$password);
$con = mysql_connect($mysql_host,$username,$password);
if (!$con) {
die("<div class='alert alert-error'><button type='button' class='close' data-dismiss='alert'>×</button><strong>Error: </strong>" . mysql_error() . "</strong></div>");
}
if (mysql_query("CREATE DATABASE $database",$con)) {
echo "<div class='alert alert-success'><button type='button' class='close' data-dismiss='alert'>×</button><strong>Success! </strong>Database created</strong></div>";
}
else {
echo "<div class='alert'><button type='button' class='close' data-dismiss='alert'>×</button><strong>Warning: </strong>" . mysql_error() . "</strong></div>";
}
@mysql_select_db($database) or die( "Unable to select database in setup.php");
$query="CREATE TABLE Artists (id int(6) PRIMARY KEY NOT NULL auto_increment, name varchar(30) NOT NULL, img varchar(60) NOT NULL)";
mysql_query($query);
# var_dump(curl_version());
$lfmmethod = "chart.getTopArtists";
$url = $lfmbase . "?method=" . $lfmmethod . $lfmkey;
echo "<p class='lead'>" . $lfmmethod . "</p>";
$response = get_page($url);
$xml = new SimpleXMLElement($response);
$data = $xml->artists->artist;
for ($i = 0; $i < sizeof($data); $i++) {
$name = (string) $data[$i]->name;
$img = $data[$i]->children();
$img = (string) $img->image[3];
$query = "INSERT INTO Artists VALUES ('', '$name', '$img')";
//$sql = 'INSERT INTO `test` ( `title` , `BODY` ) ' . "VALUES ( '$title', '$body' )"
mysql_query($query);
}
mysql_close();
// run initializer to set $username, $password, $database
mysql_connect($mysql_host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM Artists";
$result=mysql_query($query);
// recover ALL the things from this broad query
$num=mysql_numrows($result);
echo "<p style='font-weight: bold; text-align:center;'>Last.fm Database<p/>";
?>
<?php
$i=0;
while ($i < $num) {
$name=mysql_result($result,$i,"name");
$img=mysql_result($result,$i,"img");
?>
<?php
echo "<div class='media'>";
echo "<img src='" . $img . "' alt='" . $name . "' class='media-object thumbnail'/></a>";
echo "<div class='media-body'>";
echo "<h2 class='media-heading'>" . $name . "</h2>";
echo "</div></div>";
?>
<?php
++$i;
}
?>
</div>
</div>
</div>
</body>
</html>