diff --git a/class.php b/class.php
index 680e27c..16d3878 100644
--- a/class.php
+++ b/class.php
@@ -102,6 +102,37 @@ class ps4 {
}
+ function games_reorder($games,$orderby="last_played_desc") {
+ function totaltime_asc($a,$b) {
+ return ($a["game_total_time"] <= $b["game_total_time"]) ? -1 : 1;
+ }
+ function totaltime_desc($a,$b) {
+ return ($a["game_total_time"] >= $b["game_total_time"]) ? -1 : 1;
+ }
+
+
+ function firstplayed_asc($a,$b) {
+ return ($a["game_played_first"] <= $b["game_played_first"]) ? -1 : 1;
+ }
+ function firstplayed_desc($a,$b) {
+ return ($a["game_played_first"] >= $b["game_played_first"]) ? -1 : 1;
+ }
+
+ function lastplayed_asc($a,$b) {
+ if ($a["game_played_last"] == -1) { $a["game_played_last"] = (round(microtime(true) * 1000)); }
+ if ($b["game_played_last"] == -1) { $b["game_played_last"] = (round(microtime(true) * 1000)); }
+ return ($a["game_played_last"] <= $b["game_played_last"]) ? -1 : 1;
+ }
+ function lastplayed_desc($a,$b) {
+ if ($a["game_played_last"] == -1) { $a["game_played_last"] = (round(microtime(true) * 1000)); }
+ if ($b["game_played_last"] == -1) { $b["game_played_last"] = (round(microtime(true) * 1000)); }
+ return ($a["game_played_last"] >= $b["game_played_last"]) ? -1 : 1;
+ }
+
+ usort($games, $orderby);
+ return $games;
+ }
+
}
?>
\ No newline at end of file
diff --git a/index.php b/index.php
index 5c3b727..2ca51a7 100644
--- a/index.php
+++ b/index.php
@@ -4,6 +4,8 @@ ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
+$orderby = isset($_GET['orderby']) ? $_GET['orderby'] : "lastplayed_desc";
+
?>
@@ -14,7 +16,7 @@ error_reporting(E_ALL);
diff --git a/page.php b/page.php
index 249e7cd..140c085 100644
--- a/page.php
+++ b/page.php
@@ -5,17 +5,22 @@ $ps4 = new ps4();
$sql = "SELECT * FROM game_time";
$result = $ps4->mysql_conn($sql);
+
+$orderby = $_GET['orderby'];
+
?>
Last Updated :
+Order by () : Total Time ASC DESC - First Played ASC DESC - Last Played ASC DESC
+
+
num_rows > 0) {
// output data of each row
while ($row = $result->fetch_assoc()) {
-
$games[$row["game_id"]]["game_id"] = $row["game_id"];
$games[$row["game_id"]]["game_name"] = $row["game_name"];
isset($games[$row["game_id"]]["game_total_time"]) ?: $games[$row["game_id"]]["game_total_time"] = 0;
@@ -39,11 +44,14 @@ if ($result->num_rows > 0) {
}
}
-$currentid = "";
+// reorder
+sort($games);
+$games = $ps4->games_reorder($games, $orderby);
+
foreach ($games as $key => $value) {
echo "