This commit is contained in:
2019-07-11 12:50:54 +02:00
parent bc65070ce3
commit 7890bf2bcb
2 changed files with 3 additions and 23 deletions

View File

@@ -34,14 +34,9 @@ class Database
$this->connection->close();
}
public function getQuestions($n = 0)
public function getQuestions($n = 10)
{
if ($n == 0) {
$sql = "SELECT * FROM questions";
} else {
//n ist gesetzt
$sql = "SELECT * FROM questions LIMIT $n";
}
$sql = "SELECT * FROM questions ORDER BY RAND() LIMIT $n";
$result = $this->connection->query($sql);
$resultArray = [];
@@ -55,20 +50,4 @@ class Database
return $resultArray;
}
public function getQuestion($id)
{
$result = $this->connection->query("SELECT * FROM questions WHERE id = $id LIMIT 1");
$resultArray = [];
while ($line = $result->fetch_assoc()) {
array_push($resultArray, $line);
}
$result->free();
return $resultArray[0];
}
}

View File

@@ -1,6 +1,7 @@
<?php
require_once(__DIR__ . '/Database.php');
header('Content-Type: application/json');
$db = new Database();