如何在用户个人资料中显示仅由用户制作的内容? PHP/MySQL

发布于 11-17 10:35 字数 244 浏览 1 评论 0原文

我是编程新手。我希望有人能帮助我解决这个问题。

我有一个包含用户个人资料的网站。用户可以简单地写文章。 目前,每个用户的所有文章都显示在任何个人资料页面中,我不需要这个。 我想做一些类似“链接”文章与制作它的用户的事情。

例如..如果我观看某人的个人资料,我只会看到该用户发表的文章,或者我观看我自己的个人资料,我只会看到我发布的文章。

因此,如果有人可以告诉这样的员工,请留下信息或代码示例的回复。

谢谢!

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

迷爱2024-11-24 10:35:50

目前,您的 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.

情话已封尘2024-11-24 10:35:50

您需要设置数据库表以使其具有一定的关系质量。例如,当用户注册时,应该为他们分配某种唯一 ID,然后当将新文章添加到包含所有用户创建的文章的表中时,您应该将创作用户的唯一 ID 分配给该特定文章行。这将为您设置一个自然的 SQL 连接,您只需从具有该 ID 的文章表中选择所有文章即可检索 ID 为 1234 的用户的所有文章。

You'll need to set up your database tables to have some relational quality to them. For example, when users register, they should be assigned some sort of unique ID, and then when a new article is added to your table containing all the user-created articles, you should assign the authoring user's unique ID to that particular article row. This will set up a natural SQL join for you, upon which you can retrieve all articles for the user with the ID 1234 by simply selecting all articles from the article table with that ID.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文