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; 
}