【问题标题】:Can we filter data stored in JSON? [closed]我们可以过滤存储在 JSON 中的数据吗? [关闭]
【发布时间】:2021-08-03 09:01:14
【问题描述】:

我正在创建一个类似medium 的网站。由于我是 Web 开发的新手,所以我将 php ajax 与 mysql 数据库一起使用,并以 JSON 格式存储用户的帖子。 Click to see database structure。 标题和描述在 JSON 中。我的问题是:-

  1. 如何在用户在搜索栏中输入标题时搜索帖子。
  2. like 和 cmets 是否应该存储在同一个 JSON 文件中(多个用户可以同时评论)?
  3. 不同的帖子有不同的 JSON 会不会在 google 搜索中显示标题和描述?
  4. 我应该如何存储大数据,例如:标题、描述、喜欢、cmets,以便我可以轻松地从搜索输入中过滤。

感谢您的帮助:)

【问题讨论】:

  • 如果要搜索和过滤数据库内容,请不要将其存储为 JSON 数据。创建适当的表格。
  • 我应该在数据库表中存储数千个单词(描述)吗?喜欢和cmets呢?谢谢 :) @TangentiallyPerpendicular
  • 欢迎来到 SO!我建议新用户查看How to Ask,以获取有关以最能邀请社区提供帮助的方式提出问题的提示。这个问题缺乏重点——您在帖子中提出了四个问题,基本上要求提供有关如何实现整个网站数据层的完整教程。我建议您自己进行一些研究,或者寻找一个更适合对话和指导的网站,而不是 SO,后者旨在进行简单而具体的问答。祝你好运,编码愉快!

标签: javascript php database posts


【解决方案1】:

“你能” - 是的。 你应该不。

您将需要 几个 相关的表,最少 articlescommentsusers 并且可能更多,因为您想要存储附件也在不同的表中。 一般 JSON 不应用于您希望搜索/索引的数据。更多商店方便。

示例表结构。这是为了让“汁液流动”和“为您指明正确的方向”,它应该逐字逐句地转化为生产数据库。

如果你使用下面的,如果你想搜索包含“猫”这个词的文章,你只需使用

SELECT * FROM articles WHERE content like '%cats%';

文章

column name column type
id int, autoincrement
title varchar(255)
content text
created_by int, Foreign Key users.id
created_on datetime, default now
last_updated_by int, Foreign Key users.id
last_updated_on datetime, default now, change on update

cmets

column name column type
id int, autoincrement
article_id int, Foreign Key articles.id
content text
created_by int, Foreign Key users.id
created_on datetime, default now
last_updated_by int, Foreign Key users.id
last_updated_on datetime, default now, change on update

用户

column name column type
id int, autoincrement
name varchar(255)
username varchar(255)
email text
password varchar(255) STORE HASHES NOT PLAINTEXT
created_on datetime, default now

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-06
    • 1970-01-01
    • 2020-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多