I want the request not to display a user with id equal to 1

$user_id = 1; mysqli_query($db, "SELECT * FROM tb_users WHERE name LIKE '%$user%' OR username LIKE '%$user%' AND user_id !=".$user_id); 

This code vseravno displays this user. Where is my mistake?

  • one
    if you use both predicates - OR and AND then the conditions to which OR applies should be wrapped with brackets: WHERE (name LIKE '%$user%' OR username LIKE '%$user%') AND user_id !=".$user_id - MaxU

1 answer 1

It is necessary to group the conditions correctly.

 SELECT * FROM tb_users WHERE (name LIKE '%$user%' OR username LIKE '%$user%') AND user_id != $user_id