$sort_direction_upper = strtoupper($sort_direction); $other_direction_upper = $sort_direction_upper != 'ASC' ? 'ASC' : 'DESC'; if (in_array($sort_column, $sort_flags)){ $query_sort = 'robots.robot_flag_'.$sort_column.' '.$sort_direction_upper; } else { $query_sort = 'robots.robot_'.$sort_column.' '.$sort_direction_upper; } // Count the total number of users first $robot_total_count = $db->get_value("SELECT count(robot_id) AS total FROM mmrpg_index_robots AS robots WHERE robots.robot_id <> 0 AND robots.robot_token <> 'robot' AND robot_class = '{$object_class_token}';", 'total'); // If the requested page would go over the limit, floor it if (ceil($show_limit * $sheet_number) > $robot_total_count){ $sheet_number = ceil($robot_total_count / $show_limit); $row_offset = $show_limit * ($sheet_number - 1); } // Collect a list of all users in the database $robot_fields = rpg_robot::get_index_fields(true); $robot_query = "SELECT {$robot_fields} FROM mmrpg_index_robots AS robots WHERE robots.robot_id <> 0 AND robots.robot_token <> 'robot' AND robot_class = '{$object_class_token}' ORDER BY {$query_sort} LIMIT {$row_offset}, {$show_limit} ;"; $robot_index = $db->get_array_list($robot_query, 'robot_id'); $robot_index_count = !empty($robot_index) ? count($robot_index) : 0; // Collect a list of completed robot sprite tokens $random_sprite = $db->get_value("SELECT robot_image FROM mmrpg_index_robots WHERE robot_image <> 'robot' AND robot_class = '{$object_class_token}' AND robot_image_size = 40 AND robot_flag_complete = 1 ORDER BY RAND() LIMIT 1;", 'robot_image'); // Calculate the number of sheets to display $num_sheets = ceil($robot_total_count / $show_limit);