php - I have a quiz and I want to get random questions (no repeat)
As the title said, I have a huge problem with a PHP script. I want to extract(Get) random questions from my database and after that display it.I want the script to look like here: http://www.filebox.ro/download.php?key=d07a7jdcf2ouwu62 but with a MySQL database, and a admin dashboard for administrating questions and users. Here is my script: http://fbx.ro/hxsztelz2chq1ekk
Here is my index.php As you see on line 6 I don't know how to do it... If you can teach me how to extract more than 1 question, like a quiz (aprox.:20 random questions)
<?php
include("config.php");
?>
<?php
session_start();
$sql = "select * from quiz order by rand() LIMIT 1";
$result = mysql_query($sql);
$row = mysql_fetch_object($result);
$question = "$row->questions";
$correctanswer = "$row->answers";
$money = '1';
$today = date('Y-m-d');
if (isset($_POST['submitted'])) {
if (empty($_POST['answer']) || empty($_POST['id'])) {
echo '<p><span class="page_speed_865619382">Trebuie sa introduci un raspuns!</span></p>';
} else {
$answer = $_POST['answer'];
$sql_answer = "select * from quiz where id = '".addslashes($_POST["id"])."'";
$result1 = mysql_query($sql_answer);
$row1 = mysql_fetch_object($result1);
$correctanswer = $row1->answers;
if (strtolower($answer) == strtolower($correctanswer))
{
echo 'Bravo, ai raspuns corect!';
$sql3= "INSERT INTO money VALUES ('','$money','$today')";
$res3 = mysql_query($sql3);
}
elseif (strtolower($answer) != strtolower($correctanswer)){
echo 'Raspuns gresit! Raspunsul corect era '.$correctanswer.'.';
}
}
}
?>
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post">
<?php echo "Intrebare: $question"; ?>
<br>
Raspuns: <input maxlength="60" name="answer" size="25" type="input">
<input name="id" type="hidden" value="<?php echo $row->id ?>">
<input name="submit" type="submit" value="Go">
<input name="submitted" type="hidden" value="TRUE">
</form>
REZULTATE:
<?php
$query1="SELECT money, data, Sum(money) AS SumOfMoney FROM money GROUP BY DATE_FORMAT(data, '%M %d, %Y') = NOW()";
$result1=mysql_query($query1);
$row1=mysql_fetch_assoc($result1);
echo '<br>Total: '.$row1['SumOfMoney'].' puncte
';
?>
Answer
Solution:
to get a random row from mysql database you can try this:
if you want to show them just once in each session you could use $_SESSION variable to keep already displayed questions and exclude those in your query.
if you need help using session to keep and exclude asked questions I can add answer to those as well.
Answer
Solution: