2017-09-04 54 views
0

我寫這些代碼用於在我的項目中搜索功能。 如果用戶輸入正確的郵政編碼,它會顯示一個表單,如果郵政編碼錯誤,它會顯示一些我在其他條件下編寫的郵件。 但是默認情況下,當用戶第一次進入頁面時顯示else消息。 如果用戶輸入錯誤的郵政編碼,我想顯示(我在其他條件下寫入的郵件)消息?任何建議。系統默認打印其他消息php

<small>Enter your zipcode to book our service</small> 
    <?php if($this->isAllowedZipcode=="Matched"){?> 
    <div class="row"> 
    </div> 
    <?php } ?> 
    <?php } else 
    { ?> 
     <div class="row"> 
      <div class="col-sm-12 col-xs-12"> 
       <p>Sorry but our services are not available in your area. We are working hard to cover as much area as we can. Thank you for using the system.</p> 
        <?php } ?> 
+0

你的代碼似乎不完整,如果您使用的條件不明確,請重新檢查你的代碼 –

+0

''結束你的'if'。 '<?php} else'繼續__some other'if'__ –

回答

0

您的代碼似乎是不正確/不完整的,但根據您的要求,你可以做到這一點如下:

<small>Enter your zipcode to book our service</small> 
    <?php if($this->isAllowedZipcode=="Matched"){ ?> 
     <div class="row"> 
       //ZIPCODE MATCHED 
     </div> 
    <?php } else { ?> 
     <div class="row"> 
      <div class="col-sm-12 col-xs-12"> 
       <p>Sorry but our services are not available in your area. We are working hard to cover as much area as we can. Thank you for using the system.</p> 
      </div> 
     </div> 
    <?php } ?> 
+0

我試過但它不能正常工作 –

+0

這只是一個想法來解決你的問題,你將不得不在「如果」的條件下工作,你應該瞭解如果其他條件在php –

-1

您可以使用elseif條件時,你可以測試郵政編碼是設置,不僅else

<small>Enter your zipcode to book our service</small> 
    <?php if($this->isAllowedZipcode=="Matched"){?> 
    <div class="row"> 
    </div> 
    <?php } elseif (isset($inputZipCode)) 
    { ?> 
     <div class="row"> 
      <div class="col-sm-12 col-xs-12"> 
       <p>Sorry but our services are not available in your area. We are working hard to cover as much area as we can. Thank you for using the system.</p> 
        <?php } ?> 
+0

中工作你有相同的錯誤和主代碼m8 – Sand

+0

你做的和OP一樣的錯誤,這個額外大括號「}」的作用是什麼? –

+0

好吧,我糾正它,對不起。 – Rinos