Php mysql结果仅对好友id可见

Php mysql结果仅对好友id可见,php,mysql,Php,Mysql,我正在做一个查询,我想选择那些当用户登录时看不到但他的朋友可以看到的记录。我Ejhon doe更新状态的通知,vikram应该看到它而不是john doe。有人能帮忙吗 这是一个问题 select * from notification where title_text='Global Notification' and user_id=3 and owner_user_id != 3 and is_seen=0 order by time_stamp desc 此处用户

我正在做一个查询,我想选择那些当用户登录时看不到但他的朋友可以看到的记录。我Ejhon doe更新状态的通知,vikram应该看到它而不是john doe。有人能帮忙吗

这是一个问题

select * 
from notification 
where title_text='Global Notification'
      and user_id=3 and owner_user_id  != 3 and is_seen=0  
order by time_stamp desc
此处
用户id
是登录的用户。 而
owner\u user\u id
是进行状态更新的人

因此,当john doe进行更新(
owner\u user\u id
)时,只有vikram应该看到它(
user\u id
),而不是johndoe


select * 
from notification 
where title_text='Global Notification'
      and user_id=3 and owner_user_id  <> 3 and is_seen=0  
order by time_stamp desc

选择*
从通知
其中title_text='Global Notification'
并且用户id=3,所有者用户id=3,并且被视为0
按时间顺序\u戳记说明

首先,对消息状态使用整数(
title\u text
应该类似于
message\u type
),这对于数据库来说会更快

下一步:如果你想创建状态系统,试着做一些类似邮件系统的事情,它会有这样的字段:
id
from\u id
to\u id
message\u type
message
time\u-stamp
status
。您朋友的状态将添加到此表中,如下所示
NULL,3,15,1,1,'blablabla','2012-01-13 11:44:00',0

下一步获取所有通知(例如,消息类型=1)

您将获得当前用户(to_id=15)的所有新(状态=0)通知(消息类型=1)

如果要创建公共状态,不应在WHERE子句中检查对它们的访问。创建您读取的用户数组,并选择您未读取的用户状态(将读取状态保存到COOKIE):


此查询将在1个月内返回您朋友的所有未读状态

因此,该查询是否不起作用…?否显示没有结果,如果我使用或所有用户都可以访问此查询无朋友此查询将仅为john doe完成更新,而不是vikram在其个人资料中更新的更新在本例中,3是vikram,它的权利vikram没有看到他的更新通知,但当我将id更改为6,这是john doe的,john doe也无法看到它????我以前试过太赫兹,ny more ideads friend,谢谢你的回答谢谢你在你的问题上帮了朋友的忙我有一个很好的主意怎么做。我没有使用union,而是使用了union。在这段代码中,你能帮我解决问题吗?$sql3=mysql\u查询(“SELECT*FROM”('SELECT*FROM通知,其中title\u text='Global notification'
user\u id
=$frnid和
所有者用户id
=$frnid和
被视为
=0 order by
time\u stamp
desc”)union('select*from notification,其中title_text='Global notification'和user_id=$id和owner_user_id=$frnid和is_seen=0 order by time_stamp desc'))notification order by desc”);
SELECT * FROM 'my_messages' WHERE to_id=15 AND message_type=1 AND status=0 ORDER BY time_stamp DESC
$myFriends = array(4,17,69,254,1,24); // users id
$iHaveRead = array(12,55,1245,1245,1243); // messages id


$myNotification = mysql_query("
SELECT * FROM 'my_notifications'
WHERE 
owner_user_id IN (".implode(',',$myFriends).") 
AND 
time_stamp > DATE_SUB(NOW(), INTERVAL 1 MONTH)
AND
id NOT IN (".implode(',',iHaveRead ).") 
ORDER BY time_stamp DESC
");