我做了以下代码,以显示答案表中的给定答案编号,并显示答案值和问题库表中的正确答案值。但我需要它在一个查询中执行两个不同的MySQL查询的代码,这样的事情。
$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");
是否可以使用与上层代码类似的方法执行以下代码? `
<?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;
}
?>
答案 0 :(得分:0)
如果我没有错,您只是想在INNER JOIN
列的两个表格之间执行question_no
。像
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';