Axel Nordh 6 жил өмнө
parent
commit
250ff8678e

+ 7 - 26
Assets/Scripts/Database/OnlineDatabase.cs

@@ -532,18 +532,13 @@ public class OnlineDatabase : MonoBehaviour {
 
     internal int GetWinCondition(int gameId) {
         if (winAmount == -1) {
-            string sql = "SELECT winNumber FROM game WHERE id = " + gameId;
-            IDbConnection conn = new SqliteConnection(databaseUrl);
-            conn.Open();
-            IDbCommand cmd = conn.CreateCommand();
-            cmd.CommandText = sql;
-            IDataReader reader = cmd.ExecuteReader();
-            while (reader.Read()) {
-                this.winAmount = reader.GetInt32(0);
-            }
-            reader.Close();
-            cmd.Dispose();
-            conn.Close();
+            WWWForm form = new WWWForm();
+            form.AddField("gameId", gameId);
+
+            string response = CallOnlineDatabaseWithResponse("OnlineGames.php", form);
+
+            Int32.TryParse(response, out int winAmount);
+
         }
         return this.winAmount;
     }
@@ -611,21 +606,7 @@ public class OnlineDatabase : MonoBehaviour {
 
             questions.Add(qc);
         }
-
-        /*
-            
-                q.SetAnswerText(reader.GetInt32(2).ToString());
-                q.SetQuestionText(reader.GetString(1));
-                q.idString = reader.GetInt32(0).ToString();
-                Color32 questionCategoryColor = new Color32((byte)reader.GetInt32(7), (byte)reader.GetInt32(8), (byte)reader.GetInt32(9), (byte)reader.GetInt32(10));
-
-                q.SetQuestionCategoryColor(questionCategoryColor);
-
-                questions.Add(q);
-
         
-        */
-        // TODO Fix online call to question
         return questions;
     }
 

+ 6 - 0
dbFiles/OnlineGames.php

@@ -168,6 +168,12 @@
 		$data = $result->fetch_assoc();
 		
 		echo $data['questionsLost'];
+	} else if ($callFunction === "GetWinCondition") {
+		$sql = "SELECT winNumber FROM game WHERE id = $gameId";
+		$result = $conn->query($sql);
+		$data = $result->fetch_assoc();
+		 
+		echo $data['winNumber'];
 	}