Browse Source

Start refactor onlineGame database calls

Axel Nordh 5 years ago
parent
commit
ca456c668e
2 changed files with 10 additions and 1 deletions
  1. 3 1
      Assets/Scripts/Database/OnlineDatabase.cs
  2. 7 0
      dbFiles/OnlineGames.php

+ 3 - 1
Assets/Scripts/Database/OnlineDatabase.cs

@@ -148,7 +148,9 @@ public class OnlineDatabase : MonoBehaviour {
         public string lastPlayedDate;
         public string finishedDate;
         public string status;
-        public string playerToAct;
+        public int userId;
+        public string username;
+        public int userLockedQuestions;
     }
 
     [Serializable]

+ 7 - 0
dbFiles/OnlineGames.php

@@ -23,6 +23,13 @@
 				"WHERE game.id IN (SELECT gameId FROM gamePlayers WHERE playerId = $userId) " .
 				"AND game.status != 'FINISHED' ".
 				"ORDER BY FIELD(PlayerToAct, '$userName') DESC, lastPlayedDate DESC";
+
+		$newSql = "SELECT game.*, users.id as userId, users.username as username, gamePlayers.userLockedQuestions FROM game " + 
+			"INNER JOIN gamePlayers ON gamePlayers.gameId = game.id " + 
+			"INNER JOIN users ON users.id = playerId " +
+			"WHERE game.id IN (SELECT gameId FROM gamePlayers WHERE playerId = $userId) " + 
+			"AND game.status NOT IN ('FINISHED') " + 
+			"ORDER BY FIELD(currentPlayer, $userId) DESC, lastPlayedDate DESC";
 		$result = $conn->query($sql);
 
 		if ($result->num_rows > 0) {