简体   繁体   English

PHP / MYSQL:记录用户未定义的可选数据并进行搜索优化的最佳方法是什么?

[英]PHP/MYSQL: What should the best way to record any undefined optionals data from the user and optimized to search?

I have a table with some fixed columns id,title,created.., but there I need put some optional data from the user that I cant define a specif column, but I need this data for search from others users. 我有一个带有固定的id,title,created ..固定列的表,但是我需要从用户那里输入一些可选的数据,这些数据不能定义一个specif列,但是我需要这些数据以供其他用户搜索。 What the best way? 最好的方法是什么?

  1. Store a serialized array 存储序列化数组
  2. Leave some column optionals ( exemple:leaves any 10 column opt1,opt2,opt3...) 保留一些列可选(例如:离开任何10列opt1,opt2,opt3 ...)
  3. Create a new table (dataid,uid,key,value) and new rows for each data. 为每个数据创建一个新表(dataid,uid,key,value)和新行。

the data would be like key:value pair 数据就像是key:value对

What should the best way to record any undefined optionals data from the user and optimize to search? 记录用户未定义的可选数据并进行优化搜索的最佳方法是什么?

Good Day 美好的一天

Definitively 3). 明确地3)。 Storing a serialized array means being dependend on a language (php, json etc), and selecting via sql is impossible. 存储序列化数组意味着要依赖一种语言(php,json等),并且无法通过sql选择。 2) ist bad, because of several reasons; 2)不好,原因有几个; mainly, you are less flexible in extending and selecting. 主要是,您在扩展和选择方面不太灵活。 Create a meta table like 3), this is an established approach. 创建一个类似3)的元表,这是一种已建立的方法。

Update: 3) must be improved a bit: Create a table like this: 更新:3)必须进行一些改进:创建一个像这样的表:

UID | UID | key | 关键 value

not: 不:

UID | UID | key_value 核心价值

第三种方法是最好的,因为您可以轻松地在数据库中搜索,并且您不必担心每个用户有多少个值

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

相关问题 从两个表中检索数据的优化/最佳方法是什么? - What is the optimized/best way to retrieve data from two tables? PHP / MySQL:从登录用户输入的数据库中获取过滤数据的最佳方法是什么? - PHP/ MySQL: What is the best way to get filtered data from a database that has been inputted by a logged in user? 在PHP和MySQL中存储和搜索关键字以获取记录的最佳方法? - Best way to store and search keywords for a record in PHP and MySQL? 在php / mysql中搜索拼写错误的最佳方法是什么? - What's the best way to implement typo correction into a search in php/mysql? 过滤搜索查询的最佳方法是什么 - PHP MySQL - What is the best way to filter search queries - PHP MySQL 使用PHP搜索MySQL数据库的最佳方法是什么? - What's the best way to search a MySQL database with PHP? 在MySQL / PHP中存储用户BIRTHDATES的最佳方法是什么? - What is the best way to store user BIRTHDATES in MySQL/PHP? 从iPhone应用程序-> PHP-> MySQL保护用户密码的最佳方法是什么? - What is the best way to go about protecting a user's password going from iPhone app -> PHP -> MySQL? 在php会话中存储安全用户数据的最佳方法是什么? - What is the best way to store secure user data in php sessions? 将数组从php传递到MySQL存储过程的最佳方法是什么? - What is the best way to pass an array from php to MySQL stored procedure?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM