搜索结果错误

时间:2012-11-26 09:26:56

标签: php mysql search

这是我的搜索查询,如果没有结果匹配,我该如何显示错误, 请帮忙

 $sql="SELECT  * FROM course WHERE course_name LIKE '%" . $search_name .  "%'";
              //-run  the query against the mysql query function
              $result=mysql_query($sql);

2 个答案:

答案 0 :(得分:4)

$sql="SELECT  * FROM course WHERE course_name LIKE '%" . $search_name .  "%'";
              //-run  the query against the mysql query function
$result=mysql_query($sql);

if(mysql_num_rows($result) < 1)
{
    echo 'There were no results.';
}

答案 1 :(得分:0)

if(mysql_num_rows($sql)=="0")
{
echo "----------------"; //your code here
}