| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <?php
- error_reporting( E_ALL );
- $hostname = 'localhost';
- $username = 'narKampen';
- $pass = 'IfRLzj2HJBXA9eei';
- $database = 'narKampen';
- $conn = new mysqli($hostname, $username, $pass, $database);
-
- $gameId = $_POST["gameId"];
- $answeredQuestions = $_POST["answeredQuestions"];
- if (!$conn) {
- die("Connection Failed. ". mysqli_connect_error());
- }
- mysqli_set_charset($conn,'utf8');
-
- $sql = "SELECT questions.id, question, answer, categoryId as category, name, r,g,b,a FROM questions
- INNER JOIN questionToCategory ON questions.id = questionToCategory.questionId
- INNER JOIN category on category.id = questionToCategory.categoryId
- WHERE questionToCategory.categoryId IN (SELECT categoryId FROM gameCategories WHERE gameId = $gameId) AND
- questions.id NOT IN ($answeredQuestions)
- ORDER BY RAND() limit 1";
-
- $result = mysqli_query($conn, $sql);
-
- $json = array();
-
- if (mysqli_num_rows($result) > 0) {
- while ($row = mysqli_fetch_assoc($result)) {
- $json = array('id' => $row['id'],
- 'question' => $row['question'],
- 'answer' => $row['answer'],
- 'category' => $row['category'],
- 'categoryName' => $row['name'],
- 'r' => $row['r'],
- 'g' => $row['g'],
- 'b' => $row['b'],
- 'a' => $row['a'],);
- }
- $jsonString = json_encode($json);
- echo $jsonString;
- }
- ?>
|