向某些用户显示管理消息的最佳方法? [英] Best way to show an admin message to certain users?

查看:105
本文介绍了向某些用户显示管理消息的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用PHP/MySQL/jQuery构建一个社交网站.用户登录到我的网站后,我想查询数据库并获得管理员公告(如果存在的话).这将是一个消息框,向所有用户显示在该页面上,但单击该 X 即可,除非管理员发布新的公告消息,否则不会再次显示该消息框.因此,如果您从不单击X且数据库中存在公告消息,它将始终在页面上显示此消息框,但是,如果您单击cliX来关闭该框,则返回页面除非发布了新的管理员消息,否则不会存在.

I am building a social network site in PHP/MySQL/jQuery. Once a user is logged into my site, I would like to query the DB and get an admin announcement if one exist. This will be a message box that shows on the page to all users but it will have an X to click on it and not show it ever again until the admin post a new announcement message. So if you never click the X and there is announcement messages that exist in the db, it will always show this message box on your page, however if you did cli9ck the X to close the box, then you come back to the page it will not be there, unless there is a new admin message posted.

我知道有几种方法可以做到这一点,但我正在寻找最有效的方法.

I know there is several ways of doing this but I am looking for the most efficient way.

我有一个主意,如果我在用户表"admin_message"上添加一个额外的mysql字段并将其标记为0,那么当我发布新的管理消息时,它将把每个用户的记录更改为1,如果管理消息设置为1,然后在用户页面上显示.然后,当用户单击X隐藏该框时,它将在此处更新用户表行,并将值更改为0.

One idea I have, if I add an extra mysql field onto the user's table "admin_message" and mark it as 0, then when I post a new admin message it will change the record for every user to 1, if admin message is set to 1 then it shows on user's page. Then when the user clicks the X to hide the box, it will update there user table row and chnage the value back to 0.

我的另一个想法是使用cookie来检查用户是否选择了隐藏消息,我认为这样做会更快,但可能不那么理想,因为用户可以使用不同的计算机登录并且是否显示新消息. ,他们可能不会立即看到它.

Another idea I have is to use cookie's to check if a user has chosen to hide a message, i think this would be faster but maybe not as good, since user can log in with differnt computers and if a new message is shown, they may not see it right away.

所以我只是想知道使用额外的数据库字段是否是个坏主意?如果我有1,000,000个用户,则当我发布新的管理员消息时,我将需要更新1,000,000行以确保每个人都可以看到该消息.有没有更好的办法?同样,一旦用户登录到我的站点,我将使用一个会话来存储他们看到或隐藏消息的值,而不是每次加载页面时都查看数据库.

So I am just wondering if it is a bad idea to use the extra database field? If I had 1,000,000 users, when I posted a new admin message, then I would need to update 1,000,000 rows to make sure everyone can see the message. Is there a better way? Also once a user logs into my site I will use a session to store the value of them seeing or hiding the message instead of looking at the DB on every page load.

更新

对不起,我认为我的帖子可能有点混乱或不清楚我的确切意思,因为大多数回复都针对一个与之无关的消息系统.

Sorry I think my post might of been a little confusing or not clear on what exactly I meant because most the responses are catered to a message system which this is not anything close to.

请忘记提示词,我将尝试用其他词来解释.假设该网站上有1位管理员,那是唯一可以向用户发布消息以查看的管理员.用户只会看到1条消息,如果在网站的整个生命周期内发布了2352345234条消息,则没有关系,他们只会看到1条消息,即最新消息.

Forget the message word please I will try to explain with a different word. Let's say there is 1 admin on the site, that is the only admin who can post a message to users to see. The users will only see 1 message, if there is 2352345234 messages posted over the lifetime of the site, it won't matter, they will only see 1 message, the newest message.

现在,某些登录并在页面上看到此消息"div"的用户可能会厌倦查看它,因此他们将能够隐藏它,使其不再显示.

Now some users who log in and see this message "div" on the page might get tired of looking at it, so they will be able to hide it from ever showing again.

在该页面上显示此消息就像是是"或否"一样简单.

It will be as simple as a yes or no for showing this message on there page.

但是,如果我决定需要发布新的管理员消息以供所有用户查看,那么即使是选择隐藏而不显示管理员消息的用户也将再次看到该消息,直到他们选择不再看到该消息为止. /p>

However if I decide I need to post a new admin message for all users to see, then even a user who chose to hide and not show the admin message will still see it again until they choose to never see it again.

推荐答案

两个简单的解决方案如下:

Two simple solutions are as follows:

好:检查用户cookie,如果其中包含指示该消息已显示的标志,则不显示该消息,否则显示该消息.当用户关闭它时,更新cookie.优点:绝对简单.缺点:用户可能会看到两次相同的消息,具体取决于他们是清除Cookie还是从另一台计算机登录.

Good: Check the users cookie, if it contains a flag indicating the message was displayed don't display the message, otherwise display it. When the user closes it, update the cookie. Pros: absolutely simple. Cons: The user might see the same message twice depending on if they clear their cookies or log in from another machine.

更好:将标志存储在数据库中的某个位置(您现在可以将其存储在admin用户表中,然后向下将其分成另一个表).当用户登录时,1)将该标志保存到用户的cookie或会话,2)更新数据库,3)决定是否需要显示消息.当用户关闭消息时,更新cookie/会话和数据库.优点:用户永远不会收到两次显示该消息的信息.缺点:由于您需要维护数据库中的标志,因此需要更多的参与.

Better: Store a flag in the database somewhere (you can store it in the admin user table for now, and down the line break it out into another table). When the user logs in, 1) save this flag to the user's cookie or session, 2) update the database, 3) decide whether the message needs to be shown. When the user closes the message, updare the cookie/session and DB. Pros: User never gets shown the message twice. Cons: slightly more involved as you need to maintain the flag in the db.

实施细节: 对于该标志,您可以使用已经建议的消息ID,或者很有可能已经保留了用户的上次登录时间戳,并可以使用该ID.

Implementation details: For the flag, you could use a message id as suggested already, or more than likely you are already retaining the user's last login timestamp and could use that.

这篇关于向某些用户显示管理消息的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆