1 2 3 4 5 6 7 8 9 10 11 12
|
function condLike($field, $value) { return "$field LIKE '%$value%'"; }
function condEqual($field, $value) { return "$field='$value'"; }
function condBigger($field, $value) { return "$field>'$value'"; }
$filters['dossier'] = 'Like';
$filters['motcle'] = 'Equal';
$filters['age'] = 'Bigger';
$sql = "SELECT * FROM table";
foreach($filters as $field=>$cb) if($value=$_REQUEST[$field]) $ands[] = call_user_func("cond$cb", $field, $value);
if($ands) $sql.= " WHERE ".implode(' AND ', $ands); |
Partager