Php mysql类似标签随机消息 [英] Php mysql similar tags random messages
问题描述
首先抱歉我的英语。我想发送随机消息,但有一些条件。
我有两张桌子。用户(id,名称,标签)消息(id,发件人,收到,消息)
标签栏(书,电影,旅行)最多10个标签。数据保持这种方式。
当活跃用户发送消息时。将消息转发给X用户。规则:1。X用户:从未收到过消息的用户和x用户的标签必须与发件人最相似,而x用户之前从未收到过来自Active用户的消息。
我希望我能说出来。谢谢
我尝试过:
$ id = $ _SESSION [ id 跨度>];
$ Activeuserstags = explode( , ,$ _SESSION [ tags]);
$ query = $ db-> prepare( 选择id,来自用户的标签id!=?和id not in(从消息中选择receivedid));
$ query-> execute(array($ id));
$ user = $ query-> fetchAll(PDO :: FETCH_ASSOC);
if($ user){
foreach($ user as $ row){
$ randomusertags = explode( ,,$ row [ 标记跨度>]);
$ result = array_intersect($ Activeuserstags,$ randomusertags);
if(count($ result)> 0){
// 有类似的标签
}其他{
// 那里是没有类似的标签
}
}
id =
_SESSION [ id ]。
Activeuserstags = explode( 跨度>,
Firstly sorry for my English. I want to send random Messaging but there are some conditions.
I have two table. Users(id, name, tags) Messages(id, sender, received, message)
Tags column (book, movie, travel) max 10 tags. The data is kept this way.
When an active user sends a message. Forward the message to the X user. Rules : 1. X user: A user who has never received a message and x user's tags must most similar the sender and x user must have never received a message from an Active user before.
I hope I could tell. Thank you
What I have tried:
$id = $_SESSION["id"];
$Activeuserstags = explode(",", $_SESSION["tags"]);
$query=$db->prepare("select id,tags from users where id!=? and id not in (select receivedid from messages)");
$query->execute(array($id));
$user = $query->fetchAll(PDO::FETCH_ASSOC);
if($user){
foreach($user as $row){
$randomusertags=explode(",", $row["tags"]);
$result = array_intersect($Activeuserstags, $randomusertags);
if(count($result)>0){
// there is similar tags
}else{
// there is no similar tags
}
}
id =
_SESSION["id"];
Activeuserstags = explode(",",
这篇关于Php mysql类似标签随机消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!