my $sql = "SELECT id, name, location FROM $table WHERE ? ORDER BY ? ?"; . . . $sth->execute($condition,$sort_field,$sort_order);