-2

出于某种原因,当我显示预订引擎的结果时,它显示的结果如下:

主房间
主房间 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>
4

1 回答 1

1

据我所见,这整件事是为每一个$room. h2在每种情况下都会打印两个s。他们两个echo $room['desc'],似乎都包含你只想拥有一次的字符串。所以我猜你只是把你的第一个包裹<tr>...</tr>if ($room[desc] == "Main Room" || $room[desc] == "Main Room 2"):... endif;。和第二个在同一件事上Spare Room。但是,如果您的描述不是这四个值中的任何一个,我不知道您想做什么。现在<tr>打印两个 s 是有道理的,因为selse内部的条件<div>似乎不同。

于 2012-11-13T02:20:56.593 回答