Question: I am trying to filter users using country wise . `$country` is an array containing the name of countries. I want to run the query in such a way that if there is nothing in country then the query gives me all the rows. how can i acheive this.

I am doing this : 

```
  "SELECT * from users where country IN('".implode("','",$country)."')";

```

thanks in advance

Answer: 
```
$sql = "SELECT * FROM users";

if($country) {
    $sql .= " WHERE country IN('" . implode("','", $country) . "')";
}

```
For each filter item just check if it is NULL (i.e. don't filter the results based on this) or if it is equal/in:

```
SELECT *
FROM users
WHERE ('".implode("','",$country)."' IS NULL OR country IN('".implode("','",$country)."'))
AND ($forename IS NULL OR forename = $forename)

```