1

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.

5
  • Your first two queries are different. Make them both work and you have solution. Commented Apr 25, 2014 at 6:32
  • stackoverflow.com/questions/23285701/… Commented Apr 25, 2014 at 6:32
  • You have wrong sql sentence, and also you need to use mysqli_query not mysqli. See my answer Commented Apr 25, 2014 at 6:38
  • syntax mistake my friend Commented Apr 25, 2014 at 6:41
  • I can't believe this question was twice upvoted Commented Apr 25, 2014 at 8:26

5 Answers 5

3

Change LIKE %.$word.%' into LIKE '%$word%'

Sign up to request clarification or add additional context in comments.

Comments

0

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.

2 Comments

It's not a problem as long as one have an admiring friend who prefers one's answer over all others
@YourCommonSense, Admiring friend O.o ?
0

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%' ");

1 Comment

@YourCommonSense The question is very suspicious, sql sentence is wrong also function is wrong. I couldn't understand which library OP using or not. I have stated both of them. Do you think shall I remove PDO section?
-1

Try this

$word = 'cozy';
$select = mysqli($con,"SELECT *  FROM `review_details`    
                WHERE `category` = 'italian'    AND `review` LIKE '%$word%' ");

Comments

-1

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().

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.