This snippet will help you out if you need paging from an array
<?php
// Your array
$arr = array('PHP','HTML','XHTML','JAVA','ASP','ASPX','AJAX');
$selected = array();
// Per page
$perpage = 2;
// Count your array values
$count = count($arr)-1;
// Set page
$current_page = (@$_GET['page']) ? (abs($_GET['page']) > ceil((count($arr) / $perpage)) || !is_numeric($_GET['page'])) ? 1 : abs($_GET['page']) : 1;
// Settings and calculations
$amount_pages = ceil($count / $perpage) + 1;
$show_values_b = ($current_page - 1) * $perpage;
$show_values_e = ($current_page - 1) * $perpage + $perpage;
// Loop through the array containing your values
for ($i = 0; $i <= $count; $i++)
{
// Get values according to pages
if ($i >= $show_values_b && $i < $show_values_e)
$selected[] = $arr[$i];
}
// Show all the selected values
foreach ($selected as $show)
{
echo $show.'<br />';
}
echo '<br />';
// Paging navigation
if ($current_page > 1)
echo '<a href="?page=' . ($current_page - 1) . '">< Previous page</a> ';
echo 'Page '. $current_page .' of '. $amount_pages;
if ($current_page < $amount_pages)
echo '  <a href="?page=' . ($current_page + 1) . '" class="right">Next page ></a><br />';
?>
Mail this!
- Comments (0)
- PingBacks (0)
- TrackBacks (0)

» Latest comments