Update get_total_results function, let DB do the hard work