Mysql错误问题 - 关于LIke运算符

时间:2012-07-02 05:20:26

标签: php mysql

  

可能重复:
  mysql_fetch_array() expects parameter 1 to be resource, boolean given in select

以下是我的简单搜索查询但是显示

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in 
C:\xampp\htdocs\project\p\answer.php on line 52
No Result Found 

52行:

$numserach = mysql_num_rows($search_sql);

Php代码:

$search_sql = mysql_query("SELECT * FROM questions WHERE q_name LIKE %$search%");
            $numserach = mysql_num_rows($search_sql);

            if($numserach == 1)
            {
                echo $numserach. "Result found";
            }
            else
            {
                echo "No Result Found";
            }

感谢:)

1 个答案:

答案 0 :(得分:5)

您的查询中存在错误,请使用单引号LIKE查询部分括起来:

"SELECT * FROM questions WHERE q_name LIKE '%$search%'"

由于您遇到错误,$search_sql没有解析为sql结果资源,mysql_num_rows因此显示错误。