【问题标题】:How to check the id is booked of for specific days?如何查看特定日期的 id 是否已预订?
【发布时间】:2019-02-16 08:33:27
【问题描述】:

我有一张表,记录如下表。

id | list_id |venue_id |name | start_date          | end_date           |start_time |end_time | days 
1  |       1 |  1      |asdf |  2019-02-02 14:05:54| 2019-02-28 14:05:54|05:30      |10:00    | 1,2,3
2  |       7 |  2      |awed |  2019-02-10 15:02:24| 2019-02-20 15:02:24|07:30      |14:00    | 2,5
3  |       7 |  1      |mjgd |  2019-02-04 09:05:54| 2019-02-13 09:05:54|09:30      |18:00    | 4

现在我要做的是检查 start_time 和 end_time 范围,如果在范围内找到,然后检查 start_date 和 end_date 是否在范围内,如果找到,然后显示记录。

所以下面的查询适用于上述场景

SELECT * FROM batch_list 
WHERE venue_id=1 AND (start_date <= '2019-03-01') AND (start_time <= '13:00:00') AND (end_date >= '2019-02-04') AND (end_time >= '10:00:00')";

现在我还有一列是days。所以我正在做的是venue_id=1 预订了一天 1,2,3,4 然后显示记录。

那么我如何查看已经为 id 1 预订的天数?

那么我需要向用户查询哪些天数是否已经在表中,或者是否在场地 id=1 的表中?

function fetchBatches($venue_id,$new_batch_start_date,$new_batch_end_date,$new_batch_start_time,$new_batch_end_time,$days)
    {
$where="venue_id=$venue_id AND (start_date <= '$new_batch_end_date') AND (start_time <= '$new_batch_end_time') AND (end_date >= '$new_batch_start_date') AND (end_time >= '$new_batch_start_time')";

        $result =$this->db->select('*')    
                    ->from('batch_list')
                    ->where($where)
                    ->get()
                    ->result();
            if ($result) {
                 return $result;
            }
            else{
                 return 0;
            }

    }

你能帮我解决这个问题吗?

【问题讨论】:

  • 步骤 1. 将日期和时间存储为单个实体。然后回复我们。
  • @Strawberry,等一下,我正在编辑表格。
  • 好。完成后,请添加所需的结果。
  • 好的,现在你的时间列没有意义了。你能简单地删除它们吗?
  • @Strawberry,我在表格中添加了时间。现在它对我有好处。如果您分享示例以便更好地了解您需要在表格中使用什么类型的时间。

标签: php mysql codeigniter-3


【解决方案1】:

检查一个范围是否与另一个范围重叠的查询可能如下所示:

SELECT x.*
  FROM my_table x
 WHERE x.start_datetime < :end_datetime
   AND x.end\datetime >= :start_datetime;

但实际上你的问题比这个更广泛

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-06
    • 2023-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-26
    • 1970-01-01
    相关资源
    最近更新 更多