如何将包含字符串并具有列表的值存储到mysql数据库中 [英] How to store value that consist of string and has a list into mysql database

查看:31
本文介绍了如何将包含字符串并具有列表的值存储到mysql数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要插入到mysql数据库中的数据示例:

Data Example to be inserted into mysql db:

value 1:
"some text some text some text,
 some random number 123455,
 unordered list:
 <ul>
   <li>some list</li>
   <li>some list</li>
   <li>some list</li>
 </ul>";

value 2:
"some text some text,
 there are 2 unordered list here:
 <ul>
   <li>some list</li>
   <li>some list</li>
 </ul>
 <ul>
   <li>some list</li>
   <li>some list</li>
 </ul>
 and some more text and much more text";

这些只是我想插入到 mysql db 中的值的一个示例,其中一些值具有一个或多个列表和文本,而另一些值可能不包含列表.由于将列表 html 标签插入 mysql db 是不好的,而且我无法循环所有值并给它们列表标签,因为有些值甚至没有列表,那么最简单有效的解决方案是什么?

These are just an example of the value that I want to insert into mysql db, where some values have one or more list and texts while some others may not contain list. Since it is bad to insert list html tag into mysql db, and I can't loop all values and give them the list tag since some values does not even have a list inside it, what is the simplest and efficient solution to do this?

非常欢迎所有建议.谢谢

All suggestions are greatly welcomed. Thx

推荐答案

要做到这一点,您应该制作 3 个表.一个带有项目 ID 和文本.一个带有列表 ID,当然还有 FK 的项目 ID.以及一张包含所有列表项(id、列表项值和列表 ID 为 FK)的表.

To do that clean you should make 3 tables. one with and item ID and the Text. One with an an ID for the list, and of course the item ID as FK. And one table with all list item (id, list item value, and list ID as FK).

这篇关于如何将包含字符串并具有列表的值存储到mysql数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆