简体   繁体   English

简单的 PHP MySQL 消息客户端

[英]Simple PHP MySQL message client

I am trying to create a simple PHP MySQL driven message client.我正在尝试创建一个简单的 PHP MySQL 驱动的消息客户端。

So far I have two tables:到目前为止,我有两个表:

users which holds information about each person registered on the site.持有在网站上注册的每个人的信息的users userID , firstName , lastName etc. userIDfirstNamelastName等。

mail which contains a MessageID , fromUserID , toUserID , messageSubject , messageBody , dateSent etc. mail包含一个MessageIDfromUserIDtoUserIDmessageSubjectmessageBodydateSent等。

Users can register and then log in. Once they are logged in they can view their 'inbox'.用户可以注册然后登录。一旦他们登录,他们就可以查看他们的“收件箱”。

What I am trying to figure out is how to list all the messages, and a preview for each message saying who it is from.我想弄清楚的是如何列出所有消息,以及每条消息的预览,说明它来自谁。 Obviously I can get the fromUserID field from the mail table but that doesn't mean anything to the user, it is just a number, I want to use the userID and query the users table and pull from that the sender's first and last name.显然,我可以从mail表中获取fromUserID字段,但这对用户没有任何意义,它只是一个数字,我想使用userID并查询users表并从中提取发件人的名字和姓氏。

I know I can use JOIN but I am not sure how to go about it, or can I use a sub query?我知道我可以使用JOIN但我不知道如何去做,或者我可以使用子查询吗? What is better?什么是更好的?

Any suggestions are very welcome.任何建议都非常受欢迎。

You're going to want to join the users table, something like:您将要加入 users 表,例如:

SELECT m.*, u.*
FROM mail m
  LEFT JOIN users u ON u.id = m.fromUserID
WHERE m.toUserID == 'LoggedInUserId'

Keep the userid in session when you validate the user.验证用户时,将用户 ID 保留在会话中。 then you can get the data using the below query.然后您可以使用以下查询获取数据。 select mail.* from mail m,users u where u.user_id=m.to_user_id and u.user_id= logged in userid select mail.* from mail m,users u where u.user_id=m.to_user_id and u.user_id= login in userid

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM