Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 比较MYSQL中的两个表_Php_Mysql_Sql_Sqlite - Fatal编程技术网

Php 比较MYSQL中的两个表

Php 比较MYSQL中的两个表,php,mysql,sql,sqlite,Php,Mysql,Sql,Sqlite,我必须比较两个表,然后将它们列为复选框,而匹配的值应该被选中,而不匹配的值应该被选中 //表1 //表2 从两个表中匹配rid,其中category='uniform' 列出所有并检查匹配的rid $query = "select a.* from table1 a, table b where a.rid = b.rid and a.category = b.category"; $result = mysqli->query($query); $fetched = $result-

我必须比较两个表,然后将它们列为复选框,而匹配的值应该被选中,而不匹配的值应该被选中

//表1

//表2

从两个表中匹配rid,其中category='uniform' 列出所有并检查匹配的rid

$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']}";
}

循环浏览表1中的每一行。如果rid存在于表2中,请勾选。我也必须完成我的工作。有志愿者吗?基于rid和类别过滤器在两个表之间进行外部联接。类别值统一标记为勾号,类别为空则不标记。
id|rid | category  
1 | 1  |  uniform  
2 | 2  |  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=''  >"; }
     }