$query = 'WHERE 1=1'; $query .= " AND state='$state'" if ($state ne 'all'); $query .= " AND approved='$status'" if ($status ne 'all');