operators - MySQL <> not working - returning those results -
i'm having problem <> (not) operator.
i'm trying retrieve rows habbo_name not equal 2 given, still returning rows. has got suggestions how fix this?
code:
<?php $query = "select `user_id`, `rank`, `habbo_name`, `rating`, `branch` `personnel` status='active' , `rating` '%(sdp%' or `rating` '%/sdp)%' , (`habbo_name` <> '-jose,' , `habbo_name` <> 'tharuka$') , status='active' order `habbo_name`"; $result = $con->prepare($query); $result->execute(); while($row = $result->fetch()) { echo "<b>sdp:</b> " . htmlspecialchars($row['habbo_name']) . "<br>"; } ?>
result:
sdp: -jose, sdp: -wyatt- sdp: cpt.black sdp: dr.jacobson sdp: malwarebyte sdp: nshadow sdp: tharuka$ (dudestetson)
and
has higher precedence or
, when mixing both operators 1 needs include parentheses enforce one's desired logic. things stand, filter expression evaluated as:
where ( status = 'active' , rating '%(sdp%' ) or ( rating '%/sdp)%' , habbo_name <> '-jose,' , habbo_name <> 'tharuka$' , status = 'active' )
i suspect want instead:
where status = 'active' , (rating '%(sdp%' or rating '%/sdp)%') , habbo_name <> '-jose,' , habbo_name <> 'tharuka$'
in case, 1 can use mysql's in()
operator simplify conditions on habbo_name
:
where status = 'active' , (rating '%(sdp%' or rating '%/sdp)%') , habbo_name not in ('-jose,', 'tharuka$')
Comments
Post a Comment