效果如下:
入参:总数据、当前分页、每页数量
方法:
/** * bootstrap4风格 * @param $totalData * @param $perPage * @param $currentPage * @return string */ function bootstrap4($totalData, $perPage, $currentPage) { $totalPages = ceil($totalData / $perPage); $paginationHtml = ''; if ($totalPages > 1) { $paginationHtml .= '<ul class="pagination">'; // Previous page link if ($currentPage > 1) { $paginationHtml .= '<li class="page-item"><a class="page-link" href="?page=' . ($currentPage - 1) . '">前一页</a></li>'; } // Page links for ($i = 1; $i <= $totalPages; $i++) { if ($i == $currentPage) { $paginationHtml .= '<li class="page-item active"><a class="page-link" href="?page=' . $i . '">' . $i . '</a></li>'; } else { $paginationHtml .= '<li class="page-item"><a class="page-link" href="?page=' . $i . '">' . $i . '</a></li>'; } } // Next page link if ($currentPage < $totalPages) { $paginationHtml .= '<li class="page-item"><a class="page-link" href="?page=' . ($currentPage + 1) . '">下一页</a></li>'; } $paginationHtml .= '</ul>'; } return $paginationHtml; }
使用:
bootstrap4($total, $pageSize, $page);