I had did the below code to show the given answer number from answer table and to show answer value and the right answer value from question bank table. But I need it to do the code of two distinct MySQL query in a single query some thing like this.
$result = mysql_query("SELECT t1.*, t2.(t1.clicked_answer)
FROM Eg_Net_Solution_test_answer AS t1,
Eg_Net_Solution_test_question_bank AS t2
WHERE t1.user_serial = '10' AND
t1.area='Hamdun Pur' AND
t1.question_no=t.question_no");
Is it possible to do the below code in a similar method like the upper one? `
<?php
$given_answer_value="";
$right_answer_value="";
$question_no="";
$given_answer_no="";
$right_answer_no="";
$result=mysql_query("SELECT * from Eg_Net_Solution_test_answer where user_serial='10' AND area='Hamdun Pur'" );
while($row=mysql_fetch_array($result))
{
$question_no=$row['question_no'];//question_no is a Column of Eg_Net_Solution_test_answer table
$given_answer_no= $row['clicked_answer']; //clicked_answer is a Column of Eg_Net_Solution_test_answer table contains value a,b,c,d
$result2=mysql_query("SELECT * from $Eg_Net_Solution_test_question_bank where question_no='$question_no'" );
while($row2=mysql_fetch_array($result2))
{
$given_answer_value=$row2[$given_answer];// $given_answer is Column of Eg_Net_Solution_test_question_bank table and contains string value. Like $given_answer=a, and this colun a contains value "Prophet Muhammad RIP"
$right_answer_value=$row2[right_answer];// right_answer is Column of Eg_Net_Solution_test_question_bank table contains vale a,b,c,d
}
echo $row['question_no'];
echo "(".$row['answer']."). ".$given_answer_value;
echo "(".$row['right_answer']."). ".$right_answer_value;
}
?>
If I am not wrong, you are just meant to do a INNER JOIN
between both the tables on question_no
column. Something like
SELECT t1.*, t2.clicked_answer
from Eg_Net_Solution_test_question_bank t1
join Eg_Net_Solution_test_answer t2 on t1.question_no = t2.question_no
where t2.user_serial = '10'
and t2.area = 'Hamdun Pur';