Function.generate pagination

generate_pagination –– Pagination routine, generates page number sequence. Utilising pagination within phpBB3.

Description
Generate a pagination HTML string

Return Values
HTML string containing the relevent pagination.

Example #1 Usage
$start  = request_var('start', 0); $limit  = request_var('limit', (int) $limit);

// no result rows greater than 100 per page $limit = ($limit > 100) ? 100 : $limit;

$pagination_url = append_sid($phpbb_root_path . 'my_page.' . $phpEx, implode('&amp;', $params));

// Build a SQL Query... $sql_ary = array(   'SELECT'    => 'u.user_id, u.username, u.user_colour',    'FROM'      => array( USERS_TABLE        => 'u', ),   'WHERE'     => $db->sql_in_set('u.user_type', array(USER_NORMAL, USER_FOUNDER)), ); $sql = $db->sql_build_query('SELECT', $sql_ary); $result = $db->sql_query_limit($sql, $limit, $start);

while ($row = $db->sql_fetchrow($result)) {   // Loop though your results.

} // free the result $db->sql_freeresult($result);

// now we run the query again to get the total rows... // the query is identical except we count the rows instead $sql_ary['SELECT'] = 'COUNT(u.user_id) as total_users'; $sql = $db->sql_build_query('SELECT', $sql_ary); $result = $db->sql_query($sql);

// get the total users, this is a single row, single field. $total_users = $db->sql_fetchfield('total_users'); // free the result $db->sql_freeresult($result);

// Assign the pagination variables to the template. $template->assign_vars(array( 'PAGINATION'       => generate_pagination($pagination_url, $total_users, $limit, $start), 'PAGE_NUMBER'      => on_page($total_users, $limit, $start), 'TOTAL_USERS'      => ($total_users == 1) ? $user->lang['LIST_USER'] : sprintf($user->lang['LIST_USERS'], $total_users), ));

The HTML Template
{TOTAL_USERS} &bull; {PAGE_NUMBER} &bull; {PAGINATION} {PAGE_NUMBER} 

The Language file
'LIST_USER'    => '1 User', 'LIST_USERS'   => '%s Users',