2011-02-14 77 views
0

我該怎麼辦顯示「沒有找到結果」如果沒有匹配的結果顯示使用這樣的查詢:沒有找到結果

$query="SELECT * FROM actresses where actress_id = '$actressid' and production_full_name LIKE '%$q%'"; 
    $result=mysql_query($query); 

    $num=mysql_numrows($result); 

    mysql_close(); 

    echo ""; 

    $i=0; 
    while ($i < $num) { 

    $1=mysql_result($result,$i,"production_full_name"); 
    $2=mysql_result($result,$i,"production_id"); 
    $3=mysql_result($result,$i,"actress"); 


    echo "<br><div id=linkcontain><a id=slink href=$data/actress.php?id=$2>$3</a><div id=production>$1</div></div>"; 

    echo ""; 

     $i++; 
    } 

回答

3
if(mysql_num_rows($result) < 1) { 
    echo "No rows found"; 
} 

你的意思是?

+0

非常感謝。 – AAA 2011-02-14 19:59:39

0
if(mysql_num_rows($result) > 0) 
{ 
while($row = mysql_fetch_array($result)) 
{ 
$1 = $row['production_full_name]; 
$2 = $row['production_id']; 
$3 = $row['actress']; 
} 
} 
else 
{ 
echo "No Results Found"; 
} 

如果您正在使用函數來返回結果集,則必須使用is_方法來對結果進行類型轉換。

if(is_array($result)) 
{ 
// Logic to be implemented. 
} 
else 
{ 
echo $result; 
}