两个php查询,显示表1中的所有结果,标记为id,用户在表2中是相同的

时间:2013-07-13 16:50:24

标签: php mysqli

我有两张桌子,第一张是上传的简报。

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+  ID +  Title  +  Owner + Grade    + Location                       +    Expiry  +
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+  1  +  Test1  +  123   +  1a      +  Office 1, Office 2, Office 3  + 1404169200 +
+  2  +  Test2  +  123   +  1n      +  Office 1                      + 1404169200 +
+  3  +  Test3  +  126   +  1a      +  Office 1                      + 1404169200 +
+  4  +  Test4  +  126   +  1n,1a   +  Office 1,office 5             + 1404169200 +

第二个显示所有阅读过简报的内容

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+  unique +     item *ID from Table 1*  + iduser  +    Date      +       
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+   1     +             4               + 129     +  1394169200  +
+   2     +             4               + 128     +  1394169200  +
+   3     +             4               + 127     +  1394169200  +
+   4     +             4               + 125     +  1394169200  +

两者都运行良好,并且用于向用户显示他们有阅读的brieifng。但是我被要求添加一个列表,所以当经理搜索用户时,它会显示他们需要阅读的所有内容并标记已经阅读过的内容。 第一个查询很简单

$query ="SELECT * FROM `UPLOAD` WHERE Grade LIKE '%$GR%'//Grade of person being searched                                    
AND Location LIKE '%$LOC%'//location of person being searched
AND expiry > '$current'";//and they haven't expired
$query_result = mysql_query($query,$connection)                                 
or die("Couldn't execute query.");  
while($row = mysql_fetch_array($query_result))                           
{       
echo $row['item']."<br>";
}

此列表所有brieifngs没有问题,现在我需要在第二个表中查找一行表2项=表1 id和表2 iduser与被搜索的人相同并添加勾号或突出显示它某种程度上来说。但是我无法解决这个问题。

上面有更多的代码,它具有来自$ _POST和PHP连接等的搜索ID,但我无法将其全部放在一个页面上

1 个答案:

答案 0 :(得分:0)

要选择元素,您可以使用与

类似的内容
SELECT * FROM second_table_name
LEFT JOIN upload ON upload.id = second_table_name.item
WHERE second_table_name.userid = searched_person_id

使用正确的值代替second_table_namesearched_person_id