M Ansyori M Ansyori - 7 months ago 43
MySQL Question

PHP + MySQL 3 Condition

so I have this query below in my php code :

$query ="SELECT *
FROM material_tools_master_data
WHERE material_name like '" . $_POST["keyword"] . "%'
ORDER BY material_code
LIMIT 0,50";

It does pretty well and give me a result called 'autocomplete' in my form. The problem is, I wanna make it more complex, I want my autocomplete filter the data selection not only by
but also with
and show me exactly the
which is filtered by
= 'Measuring' OR 'Tools'.

The point is, I want to make this query works with my autocomplete. So here is my new query :

$query ="SELECT *
FROM material_tools_master_data
WHERE `material_tools_group` = 'Measuring' OR 'Tools' AND `material_name` like '" . $_POST["keyword"] . "%'
ORDER BY material_code LIMIT 0,50";

The query above is not working, the query above is giving me all the material_name rows in the table.

Any help will be much appreciated.


See warnings about PHP's deprecated API, and the proper use of prepared statements above...

$query ="
  FROM material_tools_master_data 
 WHERE material_tools_group IN('Measuring','Tools') 
   AND `material_name` LIKE '" . $_POST["keyword"] . "%' 
    BY material_code LIMIT 0,50;