I have a query to search in two tables for a vacancy.
The variables for this query are send with a form that has multiple inputs/selects. One is a text input for the title of a vacancy and the other is a dropdown with all categories a vacancy can belong to.
When I leave the text input empty and select only a category, I get all vacancies not just the ones from the selected category.
My query:
$functie = $_POST['functie'];
$branche = $_POST['branche'];
$regio = $_POST['regio'];
$search = "
SELECT cnt.title, cnt.alias, cnt.images, cnt.introtext, cnt.catid, cat.title, cat.alias
FROM snm_content cnt
LEFT JOIN snm_categories cat
ON cat.id = cnt.catid
WHERE ('".$functie."' ='' OR cnt.title LIKE '%".$functie."%')
OR ('".$branche."' ='' OR cat.title LIKE '%".$branche."%')
";
If I echo the query without typing in the text input this is what I get:
SELECT cnt.title, cnt.alias, cnt.images, cnt.introtext, cnt.catid, cat.title, cat.alias
FROM snm_content cnt
LEFT JOIN snm_categories cat
ON cat.id = cnt.catid
WHERE ('' ='' OR cnt.title LIKE '%%')
OR ('logistiek' ='' OR cat.title LIKE '%logistiek%')
snm_content
are the vacancies and snm_categories
are the categories.
How can I show only the vacancies belonging to the category that was selected?