在 MySQL 中将多个日期插入一行的最佳方法
我有一个用于预订多个日期广告的表单,这些日期是通过使用表单中的日历来选择的,然后以 JSON 格式发布。一个例子是:
[20110915, [20110918, 20110925], 20110926, 20110927]
但我在为每个广告存储这个 json 字符串时遇到问题。
- 您建议如何存储与广告相关的日期?
- 如何使用其中一个日期选择广告。
我不想将每个日期单独存储在不同的表(这使得数据库变得庞大)。
I have a form to book ads for multiple dates, which are selected by using a calendar in the form and then posted in JSON format. An example would be:
[20110915, [20110918, 20110925], 20110926, 20110927]
but I am having a problem storing this json string for each ad.
- How would you recommend storing this dates with a relation to the ad?
- How to select an ad using one of its dates.
I don't want to store each date separately in different table (which makes db bulky).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该将它们存储在关系表中,其中包含广告 ID 和预订日期。
ad_bookings
PRIMARY KEY
将为复合(ad_id, booking_date)
。样本数据为:
You should store them in a relationship table, which will have the id of the ad and the date of the booking.
ad_bookings
The
PRIMARY KEY
would be the compound(ad_id, booking_date)
.Sample data would be: