-
Notifications
You must be signed in to change notification settings - Fork 2
/
better_database.php
175 lines (139 loc) · 6.23 KB
/
better_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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<!DOCTYPE html>
<html lang="en">
<head>
<?php include("res/auth.php");
include("res/loadfunc.php");
include("res/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">
<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>
<!-- Connect to host -->
<?php
$mysql_host = "mysql13.000webhost.com";
$username="a9185905_smucker";
$password="ProfessorWhite3308";
$database="a9185905_jar";
?>
<?php
//Set up database, if necessary
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");
//Tags table holds the different tags that have been added. The first entry is the id in the table, the second entry is the id of the building in the Buildings table
//that the tag is being applied to, the third entry is the actual tag, and the fourth entry is an integer rating that tracks how many approves and disapproves users
//have given the particular tag.
$query="CREATE TABLE Tags (id int(6) PRIMARY KEY NOT NULL auto_increment, building_id int(6) NOT NULL, tag_name varchar(30) NOT NULL, rating int(6) NOT NULL)";
mysql_query($query);
//Adding a new entry into Tags
//$building_id = ;
//$tag_name = ;
//$query = "INSERT INTO Tags VALUES ('', '$building_id', '$tag_name', 0)";
//mysql_query($query);
//Buildings table tracks the different buildings that have been tagged. The first entry is the id in the table, the second entry is the name of the building, the
//third entry is the latitude of the location, and the fourth entry is the longitude of the location.
$query="CREATE TABLE Buildings (id int(6) PRIMARY KEY NOT NULL auto_increment, building_name varchar(30) NOT NULL, lat double precision(13, 10) NOT NULL, lon double precision(13, 10) NOT NULL )";
mysql_query($query);
//Adding to Buildings
//$building_name = ;
//$lat = ;
//$lon = ;
//$query = "INSERT INTO Buildings VALUES ('', '$building_name', '$lat', '$lon')";
//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 Buildings";
$result=mysql_query($query);
//Getting information from the databases
$query = "SELECT * FROM Buildings" or die(mysql_error());
/*
$query = "SELECT * FROM Buildings" WHERE $building_id= '$auto_increment' or die(mysql_error());
*/
$result = mysql_query($query);
// recover ALL the things from this broad query
$num=mysql_numrows($result);
//Old
# 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 Buildings 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 Buildings";
$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;
}
//End old
?>
</div>
</div>
</div>
</body>
</html>