簡體   English   中英

PHP If / Else語句不起作用

[英]PHP If/Else statement not working

我有一個簡單的搜索欄。

我希望它顯示在除聯系頁面之外的所有頁面上。

下面是代碼

function sidepanel()
{

     if ($this->request=='contact') { 

    $this->output('<div class="qa-sidepanel">');
    $this->output('</div>');

    } else
       $this->output('<div class="qa-sidepanel">');
       $this->search();
    $this->output('</div>');
}

在每個頁面上,它都會按原樣顯示搜索欄。

但是,當我進入聯系人頁面時,它顯示了一個非常混亂的搜索欄..但是仍然有一個搜索欄..為什么? 它根本不顯示一個。

您在其他地方缺少大括號。 沒有它,僅跳過側面板div的打開,但仍呈現搜索面板和側欄的關閉。

if ($this->request=='contact') { 
    $this->output('<div class="qa-sidepanel">');
    $this->output('</div>');
} else {
    $this->output('<div class="qa-sidepanel">');
    $this->search();
    $this->output('</div>');    
}

或者,如果整理起來,如@AdamM建議:

$this->output('<div class="qa-sidepanel">');
if ($this->request !== 'contact') { 
    $this->search();
}
$this->output('</div>');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM