2

クライアント向けのレンタル Web サイトを構築するために codeigniter を使用しています。クエリに一致するレンタル期間がない場合にのみ true を返そうとしています。基本的に、開始日と終了日のレンタルテーブルがあります。

私の顧客は日付ピッカーから開始日を選択し、終了日は開始日から設定された日数です。

そのため、クライアントがアイテムを予約できるかどうかを確認するために、それらの日付にレンタルアイテムがレンタルされているかどうかを調べたい. これが私がこれまでに持っているものであり、Codeigniters のアクティブな記録でこれを達成する必要があります...

function check_product($periodLength) {

     //This is the start time they chose from the picker
    $startTime = $_POST['date'];
     //The period length is a variable of days, so the end date would be their chosen start date plus a certain amount of days...
    $endTime = strtotime('+'.$periodLength.'day', $startTime);

    $this->db->where('productsId', $_POST['productId']);
           //This is where I need help!!! What query would give me records that are NOT between the start and end dates that i'm wanting
    $query = $this->db->get('rentals');
    $data = array();

    foreach ($query->result() as $row) {
    $data[] = array(
        'id' => $row->id,
        'customerId' => $row->customerId,
        'productsId' => $row->productsId,
        'periodStart' => $row->periodStart,
        'periodEnd' => $row->periodEnd,
        'status' => $row->status,
        'specialInstructions' => $row->specialInstructions,
        'adminNotes' => $row->adminNotes
    );
    }
    return $data;
}

私の問題のほとんどは私の頭の中にあると確信していますが、開始日から終了日までの期間がすでに予約されているかどうかを確認する必要があります。

4

1 に答える 1

2

これを試して:

    $startTime = $_POST['date'];
    $endTime = strtotime('+'.$periodLength.'day', $startTime);

    $this->db->where('productsId', $_POST['productId']);
    $this->db->where(" $startTime NOT BETWEEN periodStart AND periodEnd AND $endTime NOT BETWEEN periodStart AND periodEnd OR ($startTime < periodStart AND $endTime > periodEnd) ");
    //Since this is a complex where clause i would recommend 
    //to put enitre clause in single where statement rather than 
    //putting in different where statement. 
    //And it is upto codeigniter active record standards

     $query = $this->db->get('rentals');
于 2013-02-20T06:04:06.607 に答える