日本語:Function.generate pagination

generate_pagination -- ページ数を作成する.

説明
string generate_pagination ( string $base_url, int $num_items , int $per_page , int $start_item [, bool $add_prevnext_text [, string $tpl_prefix ]] )

例 #1 使用方法
$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), ));

HTML テンプレート
{TOTAL_USERS} &bull; {PAGE_NUMBER} &bull; {PAGINATION} {PAGE_NUMBER} 

言語ファイル
英語

'LIST_USER' => '1 User', 'LIST_USERS' => '%s Users',

日本語

'LIST_USER' => '1 人', 'LIST_USERS' => '%s 人',

参考

 * on_page
 * pagination
 * dbal::sql_build_query

Function.generate_pagination