【发布时间】:2015-06-24 08:25:52
【问题描述】:
我有一个基本的 php 聊天室。每个“房间”都有自己的桌子。在每个房间的桌子上,张贴了单独的消息,每条消息一行。列如下:
id, sender, message
在一个名为 ignore_lists 的单独表中,用户在聊天中有一个命令,可以将用户添加到他们的忽略列表中以用于私人消息目的。效果很好,我已经把那部分完全工作了。
但今天我决定尝试让它也阻止他们在“主屏幕”公共聊天中看到他们忽略列表中的人的消息。
我已经尝试过,但如果不做各种时髦的事情就无法让它工作。
这是显示我的聊天消息的功能:
function showroom($room, $len, $link){
$query3 = "SELECT * FROM(SELECT `message`, `id`, `sender` FROM `$room` ORDER BY `id` DESC LIMIT $len) AS `id` ORDER BY `id` ASC";
$result3 = mysqli_query($link, $query3); // execute the query
if (mysqli_num_rows($result3) > 0) {
while($row = mysqli_fetch_assoc($result3)) {
$showmsg = htmlspecialchars_decode($row["message"]);
echo "$showmsg<br>";
}}}
如何使用忽略列表表格以某种方式从上述函数中提取消息,但排除出现在忽略列表中的任意数量的人?
供进一步参考.. 忽略列表表只是所有用户的一张大表。每次用户将某人添加到他们的忽略列表时,它都会在 ignore_list 表中插入一行,其中包含以下列:id, person_being_ignored, name_of_ignore_list_owner
我发表了这样的声明,但没有奏效。或者更确切地说,我应该说它确实有效,但只有当您在忽略列表中只有一个人时它才有效。
query = "SELECT * FROM `ignore_lists` WHERE `ignore_owner`='$id' ORDER BY `person_being_ignored` ASC";
$result = mysqli_query($link, $query); // execute the query
if (mysqli_num_rows($result) > 0) {
while($mrow = mysqli_fetch_array($result)) {
$ignoree_name = $mrow['name_of_ignored'];
$query3 = "SELECT * FROM `$room` WHERE sender <> '$ignoree_name'";
// $query3 = "SELECT * FROM(SELECT `message`, `id`, `timestamp`, `color` FROM `$room` WHERE sender <> '$ignoree_name' ORDER BY `id` DESC LIMIT $len) AS `id` ORDER BY `id` ASC";
$result3 = mysqli_query($link, $query3); // execute the query
}
while($row = mysqli_fetch_array($result3)) {
$showmsg = htmlspecialchars_decode($row["message"]);
echo "$showmsg<br>";
}
} elseif(mysqli_num_rows($result) < 1) {
$query3 = "SELECT * FROM(SELECT `message`, `id`, `timestamp`, `color` FROM `$room` ORDER BY `id` DESC LIMIT $len) AS `id` ORDER BY `id` ASC";
$result3 = mysqli_query($link, $query3); // execute the query
if (mysqli_num_rows($result3) > 0) {
while($row = mysqli_fetch_assoc($result3)) {
$showmsg = htmlspecialchars_decode($row["message"]);
echo "$showmsg<br>";
}}}}
【问题讨论】: