如何在用户个人资料中显示仅由用户制作的内容? PHP/MySQL
我是编程新手。我希望有人能帮助我解决这个问题。
我有一个包含用户个人资料的网站。用户可以简单地写文章。 目前,每个用户的所有文章都显示在任何个人资料页面中,我不需要这个。 我想做一些类似“链接”文章与制作它的用户的事情。
例如..如果我观看某人的个人资料,我只会看到该用户发表的文章,或者我观看我自己的个人资料,我只会看到我发布的文章。
因此,如果有人可以告诉这样的员工,请留下信息或代码示例的回复。
谢谢!
I'm new in programming. I hope somebody will help me out with this one.
I have a website with user profiles. Users can simply write articles.
Currently all articles from every user are displayed in any profile page and I don't need this.
I want to do something like "link" articles with users who made it.
For example.. if I watch somebodys profile I see only articles made by this user or I watch my own profile I see only my posted articles.
So, if someone can tell something about staff like this, please leave a reply with info or code example.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
发布评论
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
目前,您的 mysql 数据库中将有一个用于用户的表,以及一个用于文章的单独表(我希望如此)。
您需要做的是修改您的文章表,使其具有一个代表创建该文章的用户的整数字段。这就是所谓的外键(您可能还想阅读关于MySQL外键。
然后,找到创建的用户一篇特定的文章,你可以使用 SQL
SELECT
您的用户表上的语句,仅查找用户 ID 等于文章中存储的用户 ID 的用户。类似,你可以“反转”这个来找到所有由特定用户撰写的文章。Currently you would have a table in your mysql database for a User, and a separate table for an Article (I hope).
What you need to do is modify your Article table so that it has an integer field which represents the user that created that article. This is what is called a foreign key (you may also want to read about MySQL foreign keys.
Then, to find the user that created a particular article, you can use a SQL
SELECT
statement on your User table to find only the users where the user id is equal to the user id stored in the article. Similarly, you can 'reverse' this to find all Articles authored by a particular User.