我有这个PHP代码
$search=$_GET['Searchusername'];
$searchuser="SELECT fullname,lastname,userName FROM users WHERE userName LIKE '%{$search}%'
OR fullname LIKE '%{$search}%' OR LIKE '%{$search}%'";
$query = mysqli_query($link, $searchuser);
$numrows = mysqli_num_rows($query);
$row = mysqli_fetch_row($query);
但它给了我2个错误
mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in
并且
mysqli_fetch_row() expects parameter 1 to be mysqli_result, boolean given in
我想让它与LIKE运算符一起使用。
答案 0 :(得分:2)
Firstoff,LIKE
是SQL语法的一部分,而不是PHP。在您的查询中,您缺少列名称,这就是它失败的原因:
$searchuser="SELECT fullname,lastname,userName
FROM users
WHERE userName LIKE '%{$search}%'
OR fullname LIKE '%{$search}%'
OR lastname LIKE '%{$search}%'";
您获得的布尔值为false
,因为查询因lastname
丢失而失败。