-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e21e8df
commit 063e5f9
Showing
3 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
//Connect to DB | ||
require("../connect.php"); | ||
|
||
$name = $_POST['n']; | ||
$time = intval($_POST['t']); | ||
$difficulty = intval($_POST['d']); | ||
|
||
if ($name === NULL || $time === NULL || $difficulty === NULL){ | ||
exit(); | ||
//exit("null values found"); | ||
} | ||
if (is_nan($time) || !is_numeric($time) || $time < 0){ | ||
exit(); | ||
//exit("invalid difficulty"); | ||
} | ||
if (is_nan($difficulty) || $difficulty > 2 || $difficulty < 0){ | ||
exit(); | ||
//exit("invalid difficulty"); | ||
} | ||
|
||
// set default name if no name was supplied | ||
if($name == "") { | ||
$name = "Unknown"; | ||
} | ||
|
||
// if name is too long for the database, only grab the first 25 letters (since database limit is a varchar(25)) | ||
$name = substr($name, 0, 25); | ||
|
||
// Prepare a query for execution | ||
$result = pg_prepare($con, "my_query", 'INSERT INTO _Table_(name, time, difficulty) VALUES($1,$2,$3)'); | ||
// Execute the prepared query. | ||
$result = pg_execute($con, "my_query", array($name, $time, $difficulty)); | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
// connection to postgresql database | ||
$conn_string = "host=localhost dbname=DB_NAME user=DB_USERNAME password=PASSWORD"; | ||
$con = pg_connect($conn_string) or die ("Could Not Connect to High Scores Database"); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
//Connect to DB | ||
require("../connect.php"); | ||
?> | ||
|
||
<!--Build HTML table to hold highscores. This implimentation uses bootstrap --> | ||
<div class="row"> | ||
<div class="" id="diffEasy"> | ||
<h4>Easy</h4> | ||
<hr> | ||
<div class="row"> | ||
<div class="col-xs-6"> | ||
<h4>Name</h4> | ||
</div> | ||
<div class="col-xs-6"> | ||
<h4>Time</h4> | ||
</div> | ||
|
||
<!-- recieve top 10 ranked Easy players --> | ||
<?php $result = pg_query($con, "SELECT name, time FROM _Table_ WHERE difficulty = 0 ORDER BY time, id LIMIT 10"); | ||
if (!$result) { | ||
echo "An error occurred.\n"; | ||
exit; | ||
} | ||
|
||
while ($row = pg_fetch_array($result)) { ?> | ||
<div class="row"> | ||
<div class="col-xs-6"> | ||
<?php echo $row['name']; ?> | ||
</div> | ||
<div class="col-xs-6"> | ||
<?php echo $row['time']; ?> | ||
</div> | ||
</div> | ||
<?php } ?> | ||
|
||
</div> | ||
</div> | ||
<div class="" id="diffMedium"> | ||
<h4>Medium</h4> | ||
<hr> | ||
<div class="row"> | ||
<div class="col-xs-6"> | ||
<h4>Name</h4> | ||
</div> | ||
<div class="col-xs-6"> | ||
<h4>Time</h4> | ||
</div> | ||
|
||
<!--Recieve top 10 ranked Medium players--> | ||
<?php $result = pg_query($con, "SELECT name, time FROM _Table_ WHERE difficulty = 1 ORDER BY time, id LIMIT 10"); | ||
while ($row = pg_fetch_array($result)) { ?> | ||
|
||
<div class="row"> | ||
<div class="col-xs-6"> | ||
<?php echo $row['name']; ?> | ||
</div> | ||
<div class="col-xs-6"> | ||
<?php echo $row['time']; ?> | ||
</div> | ||
</div> | ||
<?php } ?> | ||
</div> | ||
</div> | ||
<div class="" id="diffHard"> | ||
<h4>Hard</h4> | ||
<hr> | ||
<div class="row"> | ||
<div class="col-xs-6"> | ||
<h4>Name</h4> | ||
</div> | ||
<div class="col-xs-6"> | ||
<h4>Time</h4> | ||
</div> | ||
|
||
<!--Recieved top 10 ranked Difficult players--> | ||
<?php $result = pg_query($con, "SELECT name, time FROM _Table_ WHERE difficulty = 2 ORDER BY time, id LIMIT 10"); | ||
while ($row = pg_fetch_array($result)) { ?> | ||
<div class="row"> | ||
<div class="col-xs-6"> | ||
<?php echo $row['name']; ?> | ||
</div> | ||
<div class="col-xs-6"> | ||
<?php echo $row['time']; ?> | ||
</div> | ||
</div> | ||
<?php } ?> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
|
||
|
||
|