st_rage
06-19-2007, 03:33 AM
Hi...I am building a page that displays random questions to visitors. At the first page, the user will enter his email n be directed to another page where a random question from the database will b given. if the same email address is entered, the question that was given will not be repeated n other question will b given instead.
all the questions n answers r stored in the database with a unique id.
so far this is what i hv done.
extract ($_POST);
$id = rand(1, 14); //generate random id for random question
$query = ("SELECT * FROM email WHERE email = $email");
//check db for the email and if exist, which question was given previously
if (($query['email'] == $email) && ($query['no']==$id))
{
//if email exist and the id generated is same as 'no' in db, a new
//random id will b generated until it is unique. max is only 14, so
// when the max is reached, error msg pops out.
}
//if email does not exist in db...a random question will be given
else {
$query = ("INSERT INTO email VALUES ('$id', '$email')");
$result = mysql_query($query);
$resQ = mysql_fetch_array(mysql_query("SELECT * FROM question WHERE qid = $id"));
$resA = mysql_fetch_array(mysql_query("SELECT * FROM answer WHERE aid = $id"));
echo $resQ['quest']."<br/>";
}
?>
i hope i'm not confusing u guys. do advice
all the questions n answers r stored in the database with a unique id.
so far this is what i hv done.
extract ($_POST);
$id = rand(1, 14); //generate random id for random question
$query = ("SELECT * FROM email WHERE email = $email");
//check db for the email and if exist, which question was given previously
if (($query['email'] == $email) && ($query['no']==$id))
{
//if email exist and the id generated is same as 'no' in db, a new
//random id will b generated until it is unique. max is only 14, so
// when the max is reached, error msg pops out.
}
//if email does not exist in db...a random question will be given
else {
$query = ("INSERT INTO email VALUES ('$id', '$email')");
$result = mysql_query($query);
$resQ = mysql_fetch_array(mysql_query("SELECT * FROM question WHERE qid = $id"));
$resA = mysql_fetch_array(mysql_query("SELECT * FROM answer WHERE aid = $id"));
echo $resQ['quest']."<br/>";
}
?>
i hope i'm not confusing u guys. do advice