更新链接表
我目前添加了一些在 PHP 和 MySQL 上运行的 CMS 上管理度假出租的功能。
CMS 将房产详细信息存储在几个表中,我添加了第三个表 (letting_times
),其中包含有关人们何时入住该房产的信息。基本功能将允许用户在客人入住时添加新时间、编辑客人入住时间以及在客人不想再入住酒店时删除预订。
现在,我能想到的更新该属性占用时间的最佳方法是删除let_times数据库中包含的所有时间并再次重新插入它们。我认为执行此操作的唯一其他方法是包含表的主键,并在存在且具有值的情况下进行更新,否则进行插入,但如果删除数据行,则不会删除数据行。
有更好的方法吗?
I've currently adding a bit of functionality that manages holiday lettings on top of a CMS that runs on PHP and MySQL.
The CMS stores the property details on a couple of tables, and I'm adding a third table (letting_times
) that will contain information about when people are staying at the property. Basic functionality would allow the user to add new times when a guest is staying, edit the times that the guest is staying and remove the booking if the guest no longer wants to stay at the property.
Right now the best way that I can think of updating the times that the property is occupied is to delete all the times contained in the letting_times database and reinsert them again. The only other way that I can think to do this would be to include the table's primary key and do an update if that is present and has a value, otherwise do an insert, but this would not delete rows of data if they are removed.
Is there a better way of doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下是我对
LETTING_TIMES
表的建议:PROPERTY_ID
, pk & fkEFFECTIVE_DATE
, pk, DATE, not nullEXPIRY_DATE
, DATE, not null将 pk 设置为复合键(
PROPERTY_ID
和EFFECTIVE_DATE
) 允许您拥有给定属性的多个记录,同时阻止它们在同一天。没有一种简单的方法可以阻止 [sub?]let 重叠,但这可以减轻删除属性和属性包含的所有时间的麻烦。重新添加。Here's my recommendation for the
LETTING_TIMES
table:PROPERTY_ID
, pk & fkEFFECTIVE_DATE
, pk, DATE, not nullEXPIRY_DATE
, DATE, not nullSetting the pk to be a composite key (
PROPERTY_ID
andEFFECTIVE_DATE
) allows you to have more than one record for a given property while stopping them from being on the same day. There isn't an easy way to stop [sub?]lets from overlapping, but this would alleviate having to delete all times contained for a property & re-adding.