我必须比较两个表,然后将它们全部列为复选框,而应该检查匹配的值并且不匹配而不检查
//表格1
rid| role_name
1 | school
2 | college
3 | University
//表2
id|rid | category
1 | 1 | uniform
2 | 2 | uniform
从两个表中匹配摆脱,其中类别 = 'uniform' 列出所有并检查匹配的摆脱
$query = "select a.* from table1 a, table b where a.rid = b.rid and a.category = b.category";
$result = mysqli->query($query);
$fetched = $result->fetch_assoc();
foreach($fetched as $row){
echo "<input type='checkbox' name='{$row['rid']}' value='' checked > {$row['category']}";
}
$query = "select t1.rid, 'matched' as matching from table1 t1 where t1.rid in (
select rid from table2 where category = 'uniform')
union
select t1.rid ,'notmatched' from table1 t1 where t1.rid not in (
select rid from table2 where category = 'uniform')";
$result = mysqli->query($query);
$fetched = $result->fetch_assoc();
foreach($fetched as $row){
if($row['matching'] = 'matched'){
echo "<input type='checkbox' name='{$row['rid']}' value='' checked='checked' >"; }
else{
echo "<input type='checkbox' name='{$row['rid']}' value='' >"; }
}