2013-01-18 29 views
0

我的PHP代碼由於某種原因不工作,我在elseif上遇到錯誤。我真的不知道,因爲我從來沒有用過elseif,但我已經看到在YouTube上可以使用它,但我真的想要一些幫助來弄清楚這一點,但它之前工作正常,我設置$status1-2 = closedmsg1-2。 你知道答案或其他方式做$status1-2 = closedmsg1-2? 我也搜索了一下「String Replacer」或「String Set」,但是我找不到它。Elseif錯誤無法修復它

<?php 
//Made by Arnem\\ 

//\\Options//\\ 
$closed = 2000; 
$opend = 1500; 
$openmsg = '<p class=customfont>Streaming status: Online</p>'; 
$closemsg = '<h1 class=customfont2>Streaming is currently offline!</h1>'; 
$closemsg2 = '<p class=customfont>Streaming status: Offline</p>'; 
//DO NOT CONFIGURE UNDER THIS LINE!\\ 
$time = gmdate(H)+1 . gmdate(i); 
if ($time>$closed) 
$status1 = $closemsg; 
$status2 = $closemsg2; 
elseif ($time<$opend) 
$status1 = $closemsg; 
$status2 = $closemsg2; 
else 
$status2 = $openmsg; 

echo$status1; 
echo $status2; 
?> 

回答

2

嘗試

if ($time>$closed){ 
$status1 = $closemsg; 
$status2 = $closemsg2; 
}elseif ($time<$opend){ 
$status1 = $closemsg; 
$status2 = $closemsg2; 
}else{ 
// are you missing $status1 here? could be why its not working 
$status2 = $openmsg; 
} 

你失蹤括號{}。如果沒有他們,唯一的一次就是當它的一個陳述if/else。

+0

Ty :)的作品,但現在狀態1的東西沒有工作任何想法在那一個? – arnem

+0

我假設你到達聲明的最後一個'else'部分,並且'$ status1'沒有在那裏定義。檢查我的編輯。 – SeanWM

+0

謝謝,我沒有意識到我錯過了它 – arnem

1

你需要大括號(只有單個語句分支可以沒有它們)。

if ($time>$closed) { 
    $status1 = $closemsg; 
    $status2 = $closemsg2; 
} elseif ($time<$opend) { 
    $status1 = $closemsg; 
    $status2 = $closemsg2; 
} else { 
    $status2 = $openmsg; 
}