12-26-2016, 06:01 AM
No, the question and answers are not repeated..Each question has an id,question and answer..I was just making a thing by which I don't have to send user an OTP or activation email,my aim is to ask a random question to a newly registered user then,If he answer the question correctly (i.e his answer matches with the answer of asked question from database),then I will update a column and mark the user as active.Hope it clears what I want to achieve,but If not,then I post a code here so that It will make you clear about my question.
Assume,something like this:
qid question answer
1 2 + 2 4
2 4 / 2 2
3 2 x 2 4
My select query:
Suppose, question is 2 + 2,so user must answer 4(so it gets matched with the answer of the table). Waiting for reply.
Assume,something like this:
qid question answer
1 2 + 2 4
2 4 / 2 2
3 2 x 2 4
My select query:
PHP Code: (Select All)
$random_id = rand(1,3);
$qry = SELECT * from quest_table WHERE qid = $random_id;
$result = mysql_query($qry,$con);//$con is a php file containing connection details
while ($row = mysql_fetch_assoc($result))
{
echo $row['question];//A random question is visible in form
}
Suppose, question is 2 + 2,so user must answer 4(so it gets matched with the answer of the table). Waiting for reply.