2015-04-06 92 views
0

試圖讓這個工作..我不明白If If語句。基本上,如果場照片有一個值,我希望它顯示,如果它的值爲Null顯然會顯示其他語句。 !簡單如果其他聲明。

$row = photo 

$id = $_GET['id']; 
$sql = "SELECT * FROM menu_category WHERE id = '$id' order by sort"; 
$query = mysql_query($sql); 
while($row = mysql_fetch_array($query)) { 

echo " <h1>".$row['category_field']."</h1> "; 
echo "<div class=\"itemdescription\"> ".$row['description']."</div> "; 

$row = photo("*"); 

if ($photo = "*") { 
echo "Have a good day!"; 
} else { 
echo "Have a good night!"; 
} 

回答

0

使用空,以檢查是否存在照片與否,不是*

$row = photo 

$id = $_GET['id']; 
$sql = "SELECT * FROM menu_category WHERE id = '$id' order by sort"; 
$query = mysql_query($sql); 
while($row = mysql_fetch_assoc($query)) { 
$photo_exist = $row['photo']; 

echo " <h1>".$row['category_field']."</h1> "; 
echo "<div class=\"itemdescription\"> ".$row['description']."</div> "; 



if (!empty($photo_exist)) { 
echo "Have a good day!"; 
} else { 
echo "Have a good night!"; 
} 
+0

我得到的$ id = $ _GET [ '身份證']的錯誤;上面有$ row = photo。 –

+0

這2個錯誤是由$ _GET應該在@之前產生的,而第二個由於沒有「;」最後。然而,你應該刪除行$ row = photo(它沒有任何用處),但是如果你堅持擁有它,那麼它應該是:$ row ='photo'; $ ID = @ $ _ GET [ '身份證']; – edric