Reputation: 5407
Mysql query that works fine for me is :
SELECT *
FROM `review_details`
WHERE category = 'italian'
AND review LIKE '%cozy%';
It display results.
SELECT * FROM `review_details` WHERE category = 'italian' AND review LIKE %cozy%';
But when I execute in my php script :
$word = 'cozy';
$select = mysqli($con,"SELECT * FROM `review_details` WHERE category = 'italian' AND review LIKE %.$word.%' ");
Then it does not display any result.
Please see query is correct, when I change the condition it gives result.
Upvotes: 1
Views: 113
Reputation: 1537
Try this:
$word = 'cozy';
$select = mysqli($con,"SELECT * FROM `review_details` WHERE category = 'italian' AND review LIKE '%{$word}%' ");
But i suggest to use mysqli object oriented style instead of procedural style. Then use $con->prepare().
Upvotes: -1
Reputation: 15550
Your syntax is wrong, you need to use mysqli_query
or $mysqli->query
(PDO) , and some quote problem in sql sentence. You can use following;
$word = 'cozy';
$select = mysqli_query($con,"SELECT * FROM `review_details`
WHERE `category` = 'italian' AND `review` LIKE '%$word%' ");
Or if you are using pdo, you can use;
// $mysqli is the conn object
$word = 'cozy';
$select = $mysqli->query("SELECT * FROM `review_details`
WHERE `category` = 'italian' AND `review` LIKE '%$word%' ");
Upvotes: 0
Reputation: 68466
Rewrite it as..
$select = mysqli_query($con,"SELECT * FROM `review_details` WHERE category = 'italian' AND review LIKE '%$word%' ");
The concatenation is not at all neccessary.
It should be mysqli_query
. Pointed out by Husseyin.
Upvotes: 0
Reputation: 18600
Try this
$word = 'cozy';
$select = mysqli($con,"SELECT * FROM `review_details`
WHERE `category` = 'italian' AND `review` LIKE '%$word%' ");
Upvotes: -1