Ma no.
Devi creare una query dinamicamente.
una cosa tipo
Codice PHP:
$query = "SELECT * FROM mytable"
$where = '';
if (isset ($_REQUEST['criterio1']) {
$where = $_REQUEST['criterio1'];
}
if (isset ($_REQUEST['criterio2']) {
if (!empty($where)) { $where .= ' AND '; }
$where .= $_REQUEST['criterio2'];
}
if (isset ($_REQUEST['criterio3']) {
if (!empty($where)) { $where .= ' AND '; }
$where .= $_REQUEST['criterio3'];
}
if (isset ($_REQUEST['criterio4']) {
if (!empty($where)) { $where .= ' AND '; }
$where .= $_REQUEST['criterio4'];
}
if (!empty($where) {
$query .= ' WHERE '.$where;
}
e poi esegui la query.
In questo codice per fare prima non ho inserito alcun controllo sui criteri.
Devi assolutamente farli per evitare sql injection