0

LIKE query not working, it just output blank.

enter image description here

$stmt = $dbo->prepare("SELECT * FROM hotels WHERE h_country=:c LIKE '%m%'");
$stmt->bindValue(":c", "malaysia", PDO::PARAM_STR);
$stmt->execute();
Jonathan
  • 113
  • 12
  • Possibly this: http://stackoverflow.com/questions/11117134/implement-like-query-in-pdo – Lauri Elias Oct 21 '14 at 07:26
  • you need a `OR` or `AND` between `=` and `LIKE` and a column to match for the `LIKE` – Class Oct 21 '14 at 07:27
  • Try the solution proposed here: http://stackoverflow.com/questions/583336/how-do-i-create-a-pdo-parameterized-query-with-a-like-statement – DaveG Oct 21 '14 at 07:27

2 Answers2

1

Your SQL-Syntax is wrong, not sure what you want to obtain, but correct would be:

SELECT * FROM hotels WHERE h_country LIKE '%' || :c || '%';


--OR

SELECT * FROM hotels WHERE h_country  = :c  AND <your_column_here> LIKE '%m%';
evilive
  • 916
  • 1
  • 7
  • 24
0

Change

$stmt = $dbo->prepare("SELECT * FROM hotels WHERE h_country=:c LIKE '%m%'");

to

$stmt = $dbo->prepare("SELECT * FROM hotels WHERE h_country LIKE '%m%'");

You are either comparing values with the LIKE function or comparing with the variable ':c'. Its one or the other.

If you want to use both change to:

$stmt = $dbo->prepare("SELECT * FROM hotels WHERE h_country=:c OR  h_country LIKE '%m%'");
wayzz
  • 585
  • 6
  • 23