Explorar o código

Uppdatering av databasen kräver ny hantering av frågor

Axel Nordh %!s(int64=7) %!d(string=hai) anos
pai
achega
a3e7a7ff2e
Modificáronse 1 ficheiros con 3 adicións e 3 borrados
  1. 3 3
      dbFiles/dbAccess.php

+ 3 - 3
dbFiles/dbAccess.php

@@ -12,7 +12,8 @@
 	}
 	mysqli_set_charset($conn,'utf8');
 	
-	$sql = 'SELECT * FROM questions ORDER BY RAND() limit 1';
+	$sql = 'SELECT questions.id, question, answer, categoryId as category, name FROM questions INNER JOIN questionToCategory ON questions.id = questionToCategory.questionId INNER JOIN category on category.id = questionToCategory.categoryId ORDER BY RAND() limit 1';
+	
 	$result = mysqli_query($conn, $sql);
 	
 	$json = array();
@@ -21,8 +22,7 @@
 		while ($row = mysqli_fetch_assoc($result)) {
 			$json = array('id' => $row['id'],
 				'question' => $row['question'],
-				'answer' => $row['answer'],
-				'category' => $row['category']);
+				'answer' => $row['answer'];
 		}
 		$jsonString = json_encode($json);
 		echo $jsonString;