什么是“其他表、列相关、动态表状态”?

发布于 2024-12-11 14:04:37 字数 333 浏览 0 评论 0原文

我正在尝试在一些设计文件上绘制数据库模板,但我在依赖关系方面遇到了麻烦。

用户向网站提交内容供查看,网站根据内容的类型给予内容优先级。不过,我也希望优先级由用户设置。基本上,如果人 A 是人 B 的朋友,则人 A 提交的内容对于人 B 来说具有高优先级。人 C 不是人 A 的朋友,因此在该媒体中,人 C 提交的内容对于人 C 来说具有低优先级。

我什至不知道从哪里开始。任何朝正确方向的推动都将受到赞赏。我认为这是一个MySQL问题;然而,我使用 PHP 作为服务器端脚本语言,并且我想知道数学是否使得没有通过 MySQL 的解决方案。

目前,我正在考虑仅使用一个区域来存储好友内容,而不是搞乱优先级。

I'm trying to sketch out a database template on some design paper, and I'm having trouble with dependencies.

Users submit content to the website for viewing, and the content is given priorities based on what kind of content it is. I also would like the priorities, however, to be set by user. Basically, if person A is person B's friend, the content submitted by person A is high priority for person B. Person C is not person A's friend, so the content is low priority for person C in this medium.

I don't even know where to begin. Any push in the right direction would be appreciated. I think that this is a MySQL question; however, I am using PHP as the server-side scripting language, and I'm wondering if the math makes it so that there isn't a solution via MySQL.

I'm thinking about just using a region for friend content and not messing with priorities, currently.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

萌梦深 2024-12-18 14:04:37

只要您跟踪您需要的内容,就不会有问题,技巧就在于编写 Sql.例如,如果您有以下表结构,

person
------
id
name
otherstuff

person_releationship
-------------------
person_a_id
person_b_id
relationship_type_id

relationship_type
-------------------------
id
content_priority

content
--------------
id
stuff
person_id
user_priority

您可以编写以下语句,该语句将检索与某个人关联的所有内容,不包括他们自己的内容,按 content_priority 确定优先级

SELECT
    stuff
FROM 
    content c
    INNER JOIN person p
    ON c.person_id = p.id
    INNER JOIN person_releationship pr
    ON p.person_id = pr.person_a_id 
       or p.person_id = pr.person_b_id 
    INNER JOIN relationship_type rt
    ON pr.relationship_type_id = rt.id
WHERE
    p.id = "A"
    and c.person_id <> "A"
ORDER BY
    rt.content_priority, 
    c.user_priority

如果您愿意,您还可以使用加权优先级,因此 ORDER BY 可以是

ORDER BY
rt.content_priority *  c.user_priority

您应该注意的是,此 SQL 和表设计独立于 RDBMS 和 Web 技术。

As long as you track what you need it shouldn't be problem, the trick will be in writing the Sql. For instance if you had the following table structure

person
------
id
name
otherstuff

person_releationship
-------------------
person_a_id
person_b_id
relationship_type_id

relationship_type
-------------------------
id
content_priority

content
--------------
id
stuff
person_id
user_priority

You could write the following statement which would retrieve all the content associated with a person, excluding their own content, prioritized by content_priority

SELECT
    stuff
FROM 
    content c
    INNER JOIN person p
    ON c.person_id = p.id
    INNER JOIN person_releationship pr
    ON p.person_id = pr.person_a_id 
       or p.person_id = pr.person_b_id 
    INNER JOIN relationship_type rt
    ON pr.relationship_type_id = rt.id
WHERE
    p.id = "A"
    and c.person_id <> "A"
ORDER BY
    rt.content_priority, 
    c.user_priority

If you want you could also use weighted priority so the ORDER BY could be

ORDER BY
rt.content_priority *  c.user_priority

You should note that this SQL and table design is independent of the RDBMS and the web technology.

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