日本語:Function.generate pagination
From phpBB Development Wiki
generate_pagination -- ページ数を作成する。
説明
string generate_pagination ( string $base_url , int $num_items , int $per_page , int $start_item [, bool $add_prevnext_text [, string $tpl_prefix ]] )
パラメータ
パラメータ | 必須 | デフォルト | 使用方法 |
---|---|---|---|
base_url | はい | ||
num_items | はい | ||
per_page | はい | ||
start_item | はい | ||
add_prevnext_text | いいえ | false | |
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('&', $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 テンプレート
<ul class="linklist">
<li class="rightside pagination">{TOTAL_USERS} • <!-- IF PAGINATION --><a href="#" onclick="jumpto(); return false;" title="{L_JUMP_TO_PAGE}">{PAGE_NUMBER}</a> • <span>{PAGINATION}</span><!-- ELSE -->{PAGE_NUMBER}<!-- ENDIF --></li>
</ul>
言語ファイル
英語
'LIST_USER' => '1 User',
'LIST_USERS' => '%s Users',
日本語
'LIST_USER' => '1 人',
'LIST_USERS' => '%s 人',