Not exactly sure what you are trying to do, but you probably need to change this line (which appears about 35 lines above the section you quoted):
$link_db->select_options ("LIMIT $offset, $maxhits");
$link_db->select_options ("ORDER BY columnname DESC", "LIMIT $offset, $maxhits");
The "DESC" is optional depending on if you need to sort by ascending or descending (default is ascending).
Hope that helps.
(EDIT: fixed missing quote)