部屋の総数から予約が自動的に差し引かれるホテル予約システムに 3 つのクエリがあります。私が望むのは、これら 3 つのクエリをすべて 1 つのクエリにまとめることです。私のクエリは次のようになります。
$p =
はforeach
ループ内に$p['id']
あり、 は各ルーム クラスのID で、 は各ルーム クラスの$p['qty']
最大ルーム数です。
$a = $p['id'];
$query = mysql_query("SELECT sum(qty) FROM prereservation where '$arrival' BETWEEN arrival and departure and room_id ='$a' and status = 'active'");
while($rows = mysql_fetch_array($query))
{
$inogbuwin=$rows['sum(qty)'];
}
$query = mysql_query("SELECT sum(qty) FROM prereservation where departure BETWEEN '$arrival' and '$departure' and room_id ='$a' and status = 'active'");
while($rows = mysql_fetch_array($query))
{
$inogbuwin2=$rows['sum(qty)'];
}
$query = mysql_query("SELECT sum(qty) FROM prereservation where '$departure' BETWEEN arrival and departure and room_id ='$a' and status = 'active'");
while($rows = mysql_fetch_array($query))
{
$inogbuwin3=$rows['sum(qty)'];
}
<select>
<option value="0"></option>
<? $counter = 1; ?>
<? while ($counter <= ($p['qty'])-($inogbuwin + $inogbuwin2 + $inogbuwin3)){ ?>
<option value="<?php echo $counter ?>"><?php echo $counter ?></option>
<? $counter++;
}?>
</select>
これら 3 つのクエリの範囲の間に日付を入れるたびに、差し引かれる合計も 3 倍になります。これが、これら 3 つのクエリをすべて 1 つにしたい理由です。
たとえば、データベースにレコードがあります
arrival = 27/10/2012 and departure = 29/10/2012
範囲内で利用できない入力日付は
$arrival = 27/10/2012 and $departure = 29/10/2012
$arrival = 26/10/2012 and $departure = 27/10/2012
$arrival = 29/10/2012 and $departure = 30/10/2012
$arrival = 26/10/2012 and $departure = 30/10/2012
$arrival = 29/10/2012 and $departure = 29/10/2012
これらの 3 つのクエリの各日付は控除でもあるので、これらのクエリを 1 つにまとめたいと思います。みんなありがとう
結局、エラーを修正しましたが、問題が 1 つだけ残っていました。予約日を 1 か月だけで固定しましたが、問題は、到着と出発の入力が同じ月でない場合にも機能しません。以下に私のコードをもう一度示します。
<?
$a = $p['id'];
$query = mysql_query("SELECT
SUM(IF('$arrival' BETWEEN arrival and departure, qty, 0)) AS bu1,
SUM(IF('$departure' BETWEEN arrival and departure, qty, 0)) AS bu2,
SUM(IF(arrival > '$arrival' and departure < '$departure', qty, 0)) AS bu3
FROM prereservation WHERE room_id ='$a' and status = 'active'");
$row = mysql_fetch_array($query);
$test1 = $row['bu1'];
if ($row['bu1'] == $row['bu2']){
$test2 = $row['bu2'] - $row['bu1'];
}else{
$test2 = $row['bu2'];
}
$test3 = $row['bu3'];
?>
<select id="select" name="qty[]" style=" width:50px;" onchange="checkall()">
<option value="0"></option>
<? $counter = 1; ?>
<? while ($counter <= ($p['qty']) - ($test1 + $test2 + $test3)){ ?>
<option value="<?php echo $counter ?>"><?php echo $counter ?></option>
<? $counter++;
}?>
この予約クエリを解決する方法を教えてください。または、php コードでこれを解決する別の方法があるかもしれません。みんなありがとう。
最後に、私は終了し、解決策を見つけました。ここにあります:
$a = $p['id'];
$query1 = mysql_query("SELECT DISTINCT id, SUM(qty)
FROM prereservation
WHERE
(
( '$arival1' BETWEEN arrival AND departure ) OR
( '$departure1' BETWEEN arrival AND departure ) OR
( arrival > '$arival1' AND departure < '$departure1' )
)
AND room_id ='$a'
AND STATUS = 'active'");
while($rows1 = mysql_fetch_assoc($query1)){
$set1 = $rows1['SUM(qty)'];
}
?>
<select id="select" name="qty[]" style=" width:50px;" onchange="checkall()">
<option value="0"></option>
<? $counter = 1; ?>
<? while ($counter <= ($p['qty']) - $set1){ ?>
<option value="<?php echo $counter ?>"><?php echo $counter ?></option>
<? $counter++;
}?>
</select>
あなたのアイデアを共有してくれてありがとう、この解決策はあなたの答えの組み合わせです..ありがとうございました!!