0

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

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+  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  +

两者都可以正常工作,并且被用来向用户展示他们有要阅读的简报。但是,我被要求添加一个列表,因此当经理搜索用户时,它会显示他们需要阅读的所有简报并标记已阅读的简报。第一个查询很简单

$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,但我无法将它们全部放在一个页面上

4

1 回答 1

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_nameandsearched_person_id

于 2013-07-13T19:05:46.037 回答