I am having two tables
- question_bank(ques_id,question,answer,a,b,c,d)
- random_question_bank(user_id,q1,q2,…………,q20)
I have filled the user_id from users.
Now, i want to fill the q1,q2,…….q20 with ques_id(randomly) for every user_id.
Please, HELP with the code.
$result_user = mysql_query("INSERT INTO random_question_bank(user_id) VALUES('".$_SESSION['user_id']."')");
if($result_user)
echo('<br />user name inserted<br />');
$result = mysql_query("SELECT * FROM question_bank ORDER BY RAND() LIMIT 20");
$q = array();
$i = 1;
while($row = mysql_fetch_assoc($result))
{
$sql = "INSERT INTO random_question_bank(q.'$i')
VALUES('".$row['ques_id']."')
WHERE user_id ='".$_SESSION['user_id']."'";
$result_ques = mysql_query($sql);
$i++;
if($result_ques)
echo('<br />q'.$i.'<br />');
$i++;
}
Please try the following code:
According to my knowledge, you can not use where clause with insert statement. Hope it will work for you.