2009-12-24 82 views
1
$query = 'select column from table ...'; 

... 


$row = mysql_fetch_assoc($result); 

//now i have the result 
//but how to check if it's null or 0? 

回答

-1

可能與在選擇的標識符替換所述空:

select coalesce(column, -1) as column 
from table ... 

這樣你可以測試0或-1(NULL)。

3

什麼 Pandiya 原本是說is_null

0
if($var == '' || $var == NULL){ 
//Code 
} 
1

嘗試

$res=mysql_query(" SELECT NULL AS anullcol, 0 AS anum, '' AS emptystring "); 
var_dump(mysql_fetch_assoc($resource)); 

,並在 '===',並宣讀了 '!==' 運營商。

C.

0

您可以使用isset()函數:

$foo = 0; 
echo isset($foo) ? 'yes' : 'no'; 
echo "<br>"; 

$foo = null; 
echo isset($foo) ? 'yes' : 'no'; 

將導致

yes 
no 
0

也許你是問,如果查詢返回了什麼。因此,嘗試使用:

mysql_num_rows() 

從PHP:

檢索的行數從結果集。該命令僅對像SELECT或SHOW這樣的返回實際結果集的語句有效。要檢索受INSERT,UPDATE,REPLACE或DELETE查詢影響的行數,請使用mysql_affected_rows()。

<?php 
if (mysql_num_rows ($query) == 0){ 
echo "duh, nothing!"; 
} 
?> 
相關問題