用户将为每个问题选择单选按钮。值:是= 1,否= 0
我已从此代码中获取解决方案ID:
$ query =“SELECT solutionid FROM rule WHERE Q1 ='$ ptptn'AND Q2 ='$ parent'AND Q3 ='$ house'”;
表格规则
id | Q1 | Q2 | Q3 |solution_id
1 | 1 | 1 | 1 | 1
2 | 0 | 0 | 1 | 2
3 | 1 | 0 | 0 | 3
表格解决方案
id | S1 | S2 | S3
1 | 0.1 | 0.1 | 0.1
2 | 0.5 | 0.5 | 0.1
3 | 0.1 | 0.5 | 0.5
我想如何代码获取基于表规则中的solution_id = id的表解决方案中的所有值(S1,S2,S3)?
例如输出:
用户选择所有问题和结果显示规则1。
溶液:0.1,0.1,0.1tqvm帮助..
答案 0 :(得分:0)
一个查询怎么样?使用JOINS:
SELECT tb1.s1, tb1.s2, tb1.s3
FROM solution AS tb1
INNER JOIN rule AS tb2
ON tb1.id = tb2.solution_id
WHERE tb2.q1 = '$ptptn'
AND tb2.q2 = '$parent'
AND tb2.q3 = '$house';
或者,将solution_id用作PHP代码中的变量并输入另一个查询。假设你已经在$ row变量中提取了你的查询,所以你现在有$ row ['solution_id'];
$query = "SELECT s1, s2, s3 FROM solution WHERE id = $row['solution_id'];";