|
|
|
จะลำดับ sql query ยังไงกับระบบ จองโรงแรม เมื่อมี period ราคาโปรโมชั้น ครับ |
|
|
|
|
|
|
|
เอาโครงสร้างพร้อม ๆ กับ Capture หน้าจอมาให้ดูหน่อยครับ
|
|
|
|
|
Date :
2012-12-24 15:20:53 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
$query = mysql_query("SELECT * FROM room_period WHERE products_code = '".$_SESSION['products_code'][$i]."' AND period_type = '1' AND ((period_start <= '".$_SESSION['check_in'][$i]."' AND period_end >= '".$_SESSION['check_out'][$i]."') OR (period_end between '".$_SESSION['check_in'][$i]."' AND '".$_SESSION['check_out'][$i]."' AND period_end != '".$_SESSION['check_in'][$i]."') OR (period_start between '".$_SESSION['check_in'][$i]."' AND '".$_SESSION['check_out'][$i]."' AND period_start != '".$_SESSION['check_out'][$i]."'))") or die(mysql_error()); // Query Period From Database
$queryCount = mysql_num_rows($query);
if ($queryCount == 0){ // Not Have Result
echo "<div class=error>선택하신 기간내에 컨택가격이 없습니다. 커뮤니티란 또는 전화로 문의해주세요~</div>";
} else {
$bed_id = $_SESSION['room_id'][$i];
$mydb->strTable = "room_bedroom_detail";
$mydb->strCondition = "bedroom_id = '$bed_id'";
$objBed =$mydb->fncSelectRecord();
$bedtype_id = $objBed['bedtype_id'];
$mydb->strTable = "room_bedtype";
$mydb->strCondition = "bedtype_id = '$bedtype_id'";
$objType =$mydb->fncSelectRecord();
$room_id = $objBed['room_id'];
$mydb->strTable = "room_information";
$mydb->strCondition = "room_id = '$room_id'";
$objRoom =$mydb->fncSelectRecord();
?>
<td align="center" rowspan="<?=$queryCount; ?>"><input type="checkbox" name="chkCartNo[]" class="chkHotel" value="<?=$i; ?>"></td>
<td align="center" rowspan="<?=$queryCount; ?>"><?=$_SESSION['check_in'][$i]; ?> ~ <?=$_SESSION['check_out'][$i]; ?></td>
<td align="center" rowspan="<?=$queryCount; ?>"><?=$objRoom['room_name']; ?> / <?=$objType['bedtype_name']; ?></td>
<td align="center" rowspan="<?=$queryCount; ?>"><?=$_SESSION['room_count'][$i] ?> 개</td>
<?
$check_in = $_SESSION['check_in'][$i];
$check_out = $_SESSION['check_out'][$i];
$dayOfDate = array();
while (strtotime($check_in) < strtotime($check_out)){ // insert Check in Date to Array
$dayOfDate[] = $check_in;
$check_in = date("Y-m-d", strtotime("+1 day", strtotime($check_in)));
}
while ($objResult = mysql_fetch_array($query)){ // Loop Result From Period Query
$day_start = $objResult['period_start'];
$day_end = $objResult['period_end'];
$total_night = CalNight($_SESSION['check_in'][$i], $_SESSION['check_out'][$i], $objResult['period_start'], $objResult['period_end']); // Calculate Night In this Period
$allSumSurcharge = 0;
$surchargeQuery = mysql_query("SELECT * FROM room_period WHERE products_code = '".$_SESSION['products_code'][$i]."' AND period_type != '1' AND ((period_start <= '$day_start' AND period_end >= '$day_end') OR (period_end between '$day_start' AND '$day_end' AND period_end != '$day_start') OR (period_start between '$day_start' AND '$day_end' AND period_start != '$day_end'))") or die(mysql_error()); // Find Surcharge Period
$bedroom_id = $objBed['bedroom_id'];
$period_id = $objResult['period_id'];
$mydb->strTable = "room_bedroom_price";
$mydb->strCondition = "bedroom_id = '$bedroom_id' AND period_id = '$period_id'";
$objPrice =$mydb->fncSelectRecord();
?>
<td align="center"><?
echo $total_night;
?> 박</td>
<td align="center"><?=number_format($objPrice['bedroom_price'],0); ?> 바트</td>
<td align="center">
<?php
$in_night = array();
while(strtotime($day_start) < strtotime($day_end)){ // Insert Period Date to Array
if(in_array($day_start, $dayOfDate)){
$in_night[] = $day_start;
}
$day_start = date("Y-m-d", strtotime("+1 day", strtotime($day_start)));
}
$count_s = 0;
$count_g = 0;
$sumGaladinner = 0;
while ($surchargeResult = mysql_fetch_array($surchargeQuery)){ // Loop Result From Surcharge Query
$period_id = $surchargeResult['period_id'];
$p_start = $surchargeResult['period_start'];
$p_end = $surchargeResult['period_end'];
while (strtotime($p_start) < strtotime($p_end)){
if(in_array($p_start, $in_night)){
if($surchargeResult['period_type'] == 2){ // if this period is Surcharge
$count_s = $count_s+1;
}
if($surchargeResult['period_type'] == 3) { // if this Period is Galadinner
$mydb->strTable = "galadinner";
$mydb->strCondition = "period_id = '$period_id' ";
$objGaladinner = $mydb->fncSelectRecord();
$adult_price = $_SESSION['room_adult'][$i]*$objGaladinner['gala_adult_price'];
$child_price = $_SESSION['room_child'][$i]*$objGaladinner['gala_child_price'];
$baby_price = $_SESSION['room_babe'][$i]*$objGaladinner['gala_babe_price'];
$sumGaladinner = $adult_price+$child_price+$baby_price;
}
}
$p_start = date("Y-m-d", strtotime("+1 day", strtotime($p_start)));
}
$mydb->strTable = "surcharge";
$mydb->strCondition = "period_id = '$period_id' ";
$objSurcharge = $mydb->fncSelectRecord();
if($total_night != '0'){
$sumSurcharge = $count_s*$_SESSION['room_count'][$i]*$objSurcharge['surcharge_price'];
} else {
$sumSurcharge = 0;
}
}
//echo $count_s."<br>";
$allSumSurcharge = $sumSurcharge+$sumGaladinner; // Calculate total of Surcharge & Galadinner
echo number_format($allSumSurcharge, 0);
?>
바트
</td>
<td align="center" class="brrightnone">
<span style="color: red;font-weight:bold;">
<?
$total = CalTotal($objPrice['bedroom_price'], $total_night, $_SESSION['room_count'][$i])+$allSumSurcharge;
echo number_format(getCurrency($total), 0)." 원";
?>
</span><br>
(<?=number_format($total,0); ?> 바트)
</td>
<tr>
<?
}
}
|
ประวัติการแก้ไข 2012-12-24 15:49:24
|
|
|
|
Date :
2012-12-24 15:48:53 |
By :
Necrotorture |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ถ้าผมต้องการให้โปรแกรม แสดง ราคาที่เป็นโปรโมชั่นอย่างเดียว เมื่อเจอกรณีที่ period โปรโมชั่น อยู่ใน period ธรรมดาผมต้องลำดับ query อะไรก่อนครับ เพราะในโค้ดผม query หา period โดยที่ไม่ได้แยก โปรโมชั่น กับ ไม่โปรโมชั่นครับ
|
|
|
|
|
Date :
2012-12-24 15:54:48 |
By :
Necrotorture |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|