I am trying to write a SQL query to get the data from the database but it doesn't execute properly. Everything works properly until I add the part
AND adstatus='success'
There is no problem executing the query. The problem is adstatus
equals to pending
in database, but still it gives all the results when adstatus
is set to success
in the query with LIKE
operators.
Here is my code:
<?php
$sql = "SELECT * FROM ad WHERE adtitle LIKE '%$keyword%' OR addescription LIKE '%$keyword%' OR adcontactemail LIKE '%$keyword%' AND adstatus='success'";
$result = mysqli_query($conn, $sql);
$queryResult = mysqli_num_rows($result);
if ($queryResult > 0) {
echo 'Results found: '.$queryResult;
} else {
echo 'No results matching your serach!';
}
?>
$queryResult
values should be less than 0 since adstatus
value in database is pending
but still it prints:
Results found: 3
How to write SQL with both LIKE
operator and a WHERE
condition like above?