出于某种原因,当我显示预订引擎的结果时,它会显示如下结果:
主房间
主室2
主室
主室2
备用室
备用房2
备用室
备用房2
它应显示为:
主房间
主室2
备用室
备用房2
希望有人能够理解为什么它会从此加倍。
<?php
$array_rooms =null;
if (get_user_meta(get_current_user_id(),'admin',true)) {
$admin = true;
} else {
$admin = false;
}
?>
<head>
</head>
<body id="results">
<h1>Available <em>Rooms</em></h1>
<table>
<?php
if($array_rooms != null){
foreach($array_rooms as $key=>$room) {
$special = '';
$roomRatePlanID = 119;
if($key==0){
$room['desc'] = "Main Room";
$special = '&whp=1';
$roomRatePlanID = 68;
}
if($key==1){
$room['desc'] = "Main Room 2";
$special = '&whp=1';
$roomRatePlanID = 68;
}
if($key==2){
$room['desc'] = "Spare Room";
$special = '&whp=1';
$roomRatePlanID = 68;
}
if($key==3){
$room['desc'] = "Spare Room 2";
$special = '&whp=1';
$roomRatePlanID = 68;
}
?>
<tr<?php if (!get_user_meta(get_current_user_id(),'admin',true) && strpos($room['desc'],'Main Room') !== false) echo ' class="disabled"'; ?>>
<td>
<div>
<h2><a href="/rooms/" target="_blank"><?php echo $room['desc'] ." " . $room['available'] ;?></a></h2>
<div><?php
if ($room['desc'] == "Main Room"){
echo "<strong>Rate: $89.00</strong>';
}elseif(($room['desc'] == "Main Room 2")){
echo "<strong>$79.00</strong>";
} else{
if ($admin)
$netrate = number_format($room['rates'][119],2);
else
$netrate = number_format($room['rates'][20] - ($room['rates'][20] / 100 * get_user_meta(get_current_user_id(),'package',true)),2);
echo "Customer Rate: <strong>$".number_format($room['rates'][20],2).'</strong> / Net Rate: <strong>$'.$netrate.'</strong>';
}?></div>
<div><a href="/book/summary?roomTypeCode=<?php echo $room['roomTypeCode'] . $special;?>">Book</a></div>
</div>
</td>
</tr>
<tr<?php if (!get_user_meta(get_current_user_id(),'admin',true) && strpos($room['desc'],'Main Room') !== false) echo ' class="disabled"'; ?>>
<td>
<div>
<h2><a href="/rooms/" target="_blank"><?php echo $room['desc'] ." " . $room['available'] ;?></a></h2>
<div><?php
if ($room['desc'] == "Spare Room"){
echo "<strong>Rate: $59.00</strong>';
}elseif(($room['desc'] == "Spare Room 2")){
echo "<strong>$49.00</strong>";
} else{
if ($admin)
$netrate = number_format($room['rates'][119],2);
else
$netrate = number_format($room['rates'][21] - ($room['rates'][21] / 100 * get_user_meta(get_current_user_id(),'package',true)),2);
echo "Customer Rate: <strong>$".number_format($room['rates'][20],2).'</strong> / Net Rate: <strong>$'.$netrate.'</strong>';
}?></div>
<div><a href="/book/summary?roomTypeCode=<?php echo $room['roomTypeCode'] . $special;?>">Book</a></div>
</div>
</td>
</tr>
<?php } }else{ echo 'no results'; }?>
</body>
</html>
答案 0 :(得分:1)
据我所知,整个事情都是针对每一个$room
执行的。在每种情况下都打印h2
两个。它们都是echo $room['desc']
,它们似乎包含你只想拥有一次的字符串。所以我猜你只需将你的第一个<tr>...</tr>
包裹在if ($room[desc] == "Main Room" || $room[desc] == "Main Room 2"):
... endif;
中。第二个与Spare Room
相同。但是,如果您的描述不是这四个值,我不知道您想要做什么。现在,由于<tr>
内的else
条件看起来不同,因此打印<div>
都是有意义的。