更新链接表

发布于 2024-08-06 11:51:29 字数 328 浏览 6 评论 0原文

我目前添加了一些在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

娇女薄笑 2024-08-13 11:51:29

以下是我对 LETTING_TIMES 表的建议:

  • PROPERTY_ID, pk & fk
  • EFFECTIVE_DATE, pk, DATE, not null
  • EXPIRY_DATE, DATE, not null

将 pk 设置为复合键(PROPERTY_IDEFFECTIVE_DATE) 允许您拥有给定属性的多个记录,同时阻止它们在同一天。没有一种简单的方法可以阻止 [sub?]let 重叠,但这可以减轻删除属性和属性包含的所有时间的麻烦。重新添加。

Here's my recommendation for the LETTING_TIMES table:

  • PROPERTY_ID, pk & fk
  • EFFECTIVE_DATE, pk, DATE, not null
  • EXPIRY_DATE, DATE, not null

Setting the pk to be a composite key (PROPERTY_ID and EFFECTIVE_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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文