Wiadomo na początku includuje plik z klasa
Pilk wykonywujący:
<?php
elseif (isset($_POST['editUser'])) {
$user.class->editUser($_POST);
$users = $user.class->getUsers();
$users = $pagination->generate($users,10,$_POST['page']);
$smarty->assign('pagination', $pagination->links());
$smarty->assign('page',$_POST['page']);
$smarty->assign('get',$_POST);
$smarty->assign('users',$users);
$smarty->display('users.tpl');
}
?>
Plik zawierający klasę pagination
<?php
class pagination
{
var $page = 1; // Current Page
var $perPage = 10; // Items on each page, defaulted to 10
var $showFirstAndLast = false; // if you would like the first and last page options.
function generate($array, $perPage = 10,$page)
{
// Assign the items per page variable
$this->perPage = $perPage;
$_GET['page'] = $page;
// Assign the page variable
if (!empty($_GET['page'])) { $this->page = $_GET['page']; // using the get method
} else {
$this->page = 1; // if we don't have a page number then assume we are on the first page
}
// Take the length of the array
$this->length = count($array);
// Get the number of pages
$this->pages = ceil($this->length / $this->perPage);
// Calculate the starting point
$this->start = ceil(($this->page - 1
) * $this->perPage);
// Return the part of the array we have requested
return array_slice($array, $this->start, $this->perPage); }
function links()
{
// Initiate the links array
// Concatenate the get variables to add to the page numbering string
$queryURL = '';
foreach ($_GET as $key => $value) {
if ($key != 'page') {
$queryURL .= '&'.$key.'='.$value;
}
}
}
// If we have more then one pages
if (($this->pages) > 1)
{
// Assign the 'previous page' link into the array if we are not on the first page
if ($this->page != 1) {
if ($this->showFirstAndLast) {
}
}
// Assign all the page numbers & links to the array
for ($j = 1; $j < ($this->pages + 1); $j++) {
if ($this->page == $j) {
$links[] = ' '.$j.' '; // If we are on the same page as the current item } else {
$links[] = ' '.$j.' '; // add the link to the array }
}
// Assign the 'next page' if we are not on the last page
if ($this->page < $this->pages) {
if ($this->showFirstAndLast) {
}
}
// Push the array into a string using any some glue
}
return;
}
}
?>
<form action="operator.php" method="GET"> <input type="hidden" name="choice_stat" value="{$choice_stat}" /> {$komunikat}
{if !empty($users)}
{if !empty($pagination)}
{if !empty($page)}
<div class="pagination">{$pagination}
</div> {else}
<div class="pagination">{$pagination}
</div> {/if}
{/if}
{foreach from=$users item=user}
<tr><td><a href="index.php?user_id={$user.id}">{$user.imie}
</a></td><td>{$user.nazwisko}
</td><td>{$user.funkcja}
</td></tr> {/foreach}
{/if}
Sory, że dopiero teraz odpowiednio zedytowałem ale musiałem zrobić ręcznie bo coś zautomatu nie wychodziło :/
Podbijam temat (IMG:
http://forum.php.pl/style_emoticons/default/smile.gif) bo odpowiedzi nie uzyskałem, a na prawdę bardzo mi zależy!! Mam nadzieję, że zostanie wybaczone (IMG:
http://forum.php.pl/style_emoticons/default/winksmiley.jpg)
Ten post edytował SoSiker 10.06.2009, 12:12:06