As beginner I have been struggling to find a solution to the following situation:
I have 3 tables:
Table 1: CITIES
id|city
1|London
2|Paris
Table 2: CATEGORIES
id|category
1|category1
2|category2
Table 3: PRODUCTS
id|city|category|name|keyword
1|1|1|product1|keyword1
2|1|1|product2|keyword2
Now I need help to mysql select to display for search results, something like this:
<?php
$keyword = preg_replace('#[^a-zA-Z]#', '', $_GET['keyword']);
$city = preg_replace('#[^0-9]#', '', $_GET['city']);
$category = preg_replace('#[^0-9]#', '', $_GET['category']);
$result = mysqli_query($con,"SELECT * FROM products WHERE category = '$category' AND city = '$city' AND keyword LIKE '$keyword'");
while($row = mysqli_fetch_array($result)) {
$id = $row['id'];
$name = $row['name'];
$category = $row['category'];
$city = $row['city'];
}
?>
my url is: search.php?keyword=keyword&category=1&city=1
this is working fine but if any of arguments is missing, then is displaying 0 results
sample: search.php?keyword=&category=&city=1