<?php
$rows = 4;
$cols = 14;
mysql_connect("localhost", "Master", "password");
mysql_select_db("Ustack");
$maxCount = $rows * $cols;
$construct= "SELECT * FROM Stacks Where username='Admin' LIMIT 0, {$maxCount}";
$limit = 52;
$page = $_GET['page'];
if($page){
$start = ($page - 1) * $limit;
}else{
$start = 0;
}
$foundnum = mysql_num_rows(mysql_query($construct));
$construct = $construct.' LIMIT '.$start.' , '.$limit;
$run = mysql_query($construct);
$idList = array();
while($row = mysql_fetch_assoc($result))
{
$idList[] = $row['id'];
$tableOutput = '';
for($row=0; $row<$rows; $row++)
{
$tableOutput .= " <tr>\n";
for($col=0; $col<$cols; $col++)
{
$idIndex = ($row * $cols) + $col;
$tableOutput .= "<td>";
$tableOutput .= (isset($idList[$idIndex]) ? $idList[$idIndex] : ' ');
$tableOutput .= "</td>\n";
}
$tableOutput .= " </tr>\n";
}}
echo "<table border='0'>
$tableOutput
</table>";
// How many adjacent pages should be shown on each side?
$adjacents = 3;
// Your file name (the name of this file)
$targetpage = "test2.php";
if ($page == 0){
$page = 1;
}
$prev = $page - 1;
$next = $page + 1;
$lastpage = ceil($foundnum/$limit);
$lpm1 = $lastpage - 1;
$pagination = "";
if($lastpage > 1){
$pagination .= "<div class=\"pagination\">";
// Previous
if ($page > 1){
$pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=$prev\" style='text-decoration: none';> <strong>« previous</strong></a>";
}else{
$pagination .= "<span class=\"disabled\"> <strong>« previous</strong></span>";
}
// Pages
if ($lastpage < (7 + ($adjacents * 2))){
for ($counter = 1; $counter <= $lastpage; $counter++){
if ($counter == $page){
$pagination .= "<span class=\"current\"><strong> $counter</strong></span>";
}else{
$pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=$counter\" style='text-decoration: none';><strong> $counter</strong></a>";
}
}
}elseif($lastpage > (5 + ($adjacents * 2))){
if($page < 1 + ($adjacents * 2)){
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++){
if ($counter == $page){
$pagination .= "<span class=\"current\"><strong> $counter</strong></span>";
}else{
$pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=$counter\" style='text-decoration: none';><strong> $counter</strong></a>";
}
}
}
$pagination .= "...";
$pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=$lpm1\" style='text-decoration: none';><strong> $lpm1</strong></a>";
$pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=$lastpage\" style='text-decoration: none';><strong> $lastpage</strong></a>";
}elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2)){
$pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=1\" style='text-decoration: none';><strong> 1</strong></a>";
$pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=2\" style='text-decoration: none';><strong> 2</strong></a>";
$pagination .= "...";
for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++){
if ($counter == $page){
$pagination .= "<span class=\"current\"><strong> $counter</strong></span>";
}else{
$pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=$counter\" style='text-decoration: none';><strong> $counter</strong></a>";
}
}
$pagination .= "...";
$pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=$lpm1\" style='text-decoration: none';><strong> $lpm1</strong></a>";
$pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=$lastpage\" style='text-decoration: none';><strong> $lastpage</strong></a>";
}else{
$pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=1\" style='text-decoration: none';> 1</strong></a>";
$pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=2\" style='text-decoration: none';> 2</strong></a>";
$pagination .= "...";
for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++){
if ($counter == $page){
$pagination .= "<span class=\"current\"><strong> $counter</strong></span>";
}else{
$pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=$counter\" style='text-decoration: none';><strong> $counter</strong></a>";
}
}
}
// Next
if ($page < $counter - 1){
$pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=$next\" style='text-decoration: none';><strong> next »</strong></a>";
}else{
$pagination .= "<span class=\"disabled\"><strong> next »</strong></span>";
$pagination .= "</div>\n";
}
}
echo $pagination;
?>