Código (php-brief) [Seleccionar]
class Filter {
private $filtros = [];
function __get($filtro) {
return "$filtro IN(" . implode(",", $this->filtros[$filtro]) . ")";
}
function __construct($cadena) {
foreach (explode('&', $cadena) as $par) {
list($filtro, $valor) = explode('=', $par);
$this->filtros[$filtro][] = is_numeric($valor) ? $valor : "'$valor'";
}
}
}
$_SERVER['QUERY_STRING'] = "select_time=2&grade=3&grade=4&grade=terror&genre=amor&genre=9&genre=5&language=0";
$filtros = new Filter($_SERVER['QUERY_STRING']);
$consulta = "SELECT * FROM tblmovies WHERE $filtros->grade AND $filtros->genre AND $filtros->language AND $filtros->select_time;";
var_dump($_SERVER['QUERY_STRING'], $filtros, $consulta);