Hi,
mein Problem ist ich schreibe gerade eine Pagination Klasse und komme nicht weiter.
Ich kriege es einfach nicht hin mit dem Dynamischen teil
Die Pagination soll ein Klon werden von der ehemaligen Stage6 Seite
hier der Aktuelle Code
index.php
Pagination Klasse
paginate.php
Stylesheet
style.css
Mysql Controller
controller.php
Hier die Archiv seiten mit dem paging
http://web.archive.org/web/20071006111945/stage6.divx.com/videos/
http://web.archive.org/web/20071006211014/stage6.divx.com/videos/?page=2
http://web.archive.org/web/20071006222143/stage6.divx.com/videos/?page=3
http://web.archive.org/web/20071011004309/stage6.divx.com/videos/?page=4
http://web.archive.org/web/20071011004315/stage6.divx.com/videos/?page=5
Ich würde auch die arbeit bezahlen...
mein Problem ist ich schreibe gerade eine Pagination Klasse und komme nicht weiter.
Ich kriege es einfach nicht hin mit dem Dynamischen teil
Die Pagination soll ein Klon werden von der ehemaligen Stage6 Seite
hier der Aktuelle Code
index.php
PHP:
<?php require_once __DIR__.'/controller.php'; ?>
<html>
<head>
<title>Pagination</title>
</head>
<link rel="stylesheet" href="style.css">
<body>
<div class="option">
<span>
<?php echo 'Page '.$pagin->current_page.' of '.$pagin->total_pages; ?>
</span>
</div>
<table>
<tr>
<th>No</th>
<th>Name</th>
<th>Code</th>
<th>District</th>
<th>Population</th>
</tr>
<?php foreach($pagin->data as $data) : ?>
<tr>
<td class="no"><?php echo $pagin->pos++;?></td>
<td><?php echo $data['video_id'];?></td>
<td><?php echo $data['video_title'];?></td>
<td><?php echo $data['ID'];?></td>
<td><?php echo $data['ID'];?></td>
</tr>
<?php endforeach; ?>
</table>
<div class='pagination'>
<?php
echo $pagin->showStage6Paging();
?>
</div>
<?php echo $pagin->multi();?>
Pagination Klasse
paginate.php
PHP:
<?php
class Paginate {
public
$current,
$limit,
$total,
$offset,
$total_pages,
$data = array(),
$pos,
$residu,
$interval,
$range;
public function __construct($page, $display, $range = 5, $normalize = true) {
$this->normalize = $normalize;
$this->current_page = (int) $page;
$this->limit = (int) $display;
if($this->normalize && $this->current_page < 1) $this->current_page = 1;
$this->setRange($range);
}
public function setTotal($total) {
$this->total = (int) $total;
$this->total_pages = ceil($this->total / $this->limit);
if($this->normalize && $this->current_page > $this->total_pages)
$this->current_page = $this->total_pages;
$this->offset = ($this->current_page - 1) * $this->limit;
$this->pos = $this->offset + 1;
}
public function currentStartPage1($showP1)
{
if($this->current_page == 1 && $showP1)
{
if($this->current_page == $this->current_page)
{
?>
<span class='pagination-selected'><?php echo $this->current_page;?></span>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->current_page+1); ?>"><?php echo $this->current_page+1; ?></a>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->current_page+2); ?>"><?php echo $this->current_page+2; ?></a>
<?php
}
else
{
?>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->current_page+1); ?>"><?php echo $this->current_page+1; ?></a>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->current_page+2); ?>"><?php echo $this->current_page+2; ?></a>
<?php
}
}
}
public function currentStartPage2($showP2)
{
if($this->current_page == 2 && $showP2)
{
if($this->current_page == $this->current_page)
{
?>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->current_page-1); ?>"><?php echo $this->current_page-1; ?></a>
<span class='pagination-selected'><?php echo $this->current_page;?></span>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->current_page+1); ?>"><?php echo $this->current_page+1; ?></a>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->current_page+2); ?>"><?php echo $this->current_page+2; ?></a>
<?php
}
else
{
?>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->current_page+1); ?>"><?php echo $this->current_page+1; ?></a>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->current_page+2); ?>"><?php echo $this->current_page+2; ?></a>
<?php
}
}
}
public function currentStartPage3($showP3)
{
if($this->current_page == 3 && $showP3)
{
if($this->current_page == $this->current_page)
{
?>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->current_page-2); ?>"><?php echo $this->current_page-2; ?></a>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->current_page-1); ?>"><?php echo $this->current_page-1; ?></a>
<span class='pagination-selected'><?php echo $this->current_page;?></span>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->current_page+1); ?>"><?php echo $this->current_page+1; ?></a>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->current_page+2); ?>"><?php echo $this->current_page+2; ?></a>
<?php
}
else
{
?>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->current_page+1); ?>"><?php echo $this->current_page+1; ?></a>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->current_page+2); ?>"><?php echo $this->current_page+2; ?></a>
<?php
}
}
}
public function currentStartPage4($showP4)
{
if($this->current_page == 4 && $showP4)
{
if($this->current_page == $this->current_page)
{
?>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->current_page-3); ?>"><?php echo $this->current_page-3; ?></a>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->current_page-2); ?>"><?php echo $this->current_page-2; ?></a>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->current_page-1); ?>"><?php echo $this->current_page-1; ?></a>
<span class='pagination-selected'><?php echo $this->current_page;?></span>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->current_page+1); ?>"><?php echo $this->current_page+1; ?></a>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->current_page+2); ?>"><?php echo $this->current_page+2; ?></a>
<?php
}
else
{
?>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->current_page+1); ?>"><?php echo $this->current_page+1; ?></a></span>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->current_page+2); ?>"><?php echo $this->current_page+2; ?></a></span>
<?php
}
}
}
public function showThreePagesStart($showPS)
{
if($showPS)
{
?>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->total_pages / $this->total_pages); ?>"><?php echo $this->total_pages / $this->total_pages; ?></a>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->total_pages / $this->total_pages + 1); ?>"><?php echo $this->total_pages / $this->total_pages + 1; ?></a>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->total_pages / $this->total_pages + 2); ?>"><?php echo $this->total_pages / $this->total_pages + 2; ?></a>
<?php
}
}
public function showThreePagesEnd($showPE)
{
if($showPE)
{
?>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->total_pages - 2); ?>"><?php echo $this->total_pages - 2; ?></a>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->total_pages - 1); ?>"><?php echo $this->total_pages - 1; ?></a>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->total_pages + 1); ?>"><?php echo $this->total_pages + 1; ?></a>
<?php
}
}
public function currentEndPage1($showE1)
{
if($this->current_page == $this->total_pages - 1 && $showE1)
{
if($this->current_page == $this->current_page)
{
?>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->current_page - 2); ?>"><?php echo $this->current_page - 2; ?></a>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->current_page - 1); ?>"><?php echo $this->current_page - 1; ?></a>
<span class='pagination-selected'><?php echo $this->current_page;?></span>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->current_page + 1); ?>"><?php echo $this->current_page + 1; ?></a>
<?php
}
else
{
?>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->current_page+1); ?>"><?php echo $this->current_page+1; ?></a>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->current_page+2); ?>"><?php echo $this->current_page+2; ?></a>
<?php
}
}
}
public function currentEndPage2($showE2)
{
if($this->current_page == $this->total_pages - 2 && $showE2)
{
if($this->current_page == $this->current_page)
{
?>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->current_page-2); ?>"><?php echo $this->current_page-2; ?></a>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->current_page-1); ?>"><?php echo $this->current_page-1; ?></a>
<span class='pagination-selected'><?php echo $this->current_page;?></span>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->current_page+1); ?>"><?php echo $this->current_page+1; ?></a>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->current_page+2); ?>"><?php echo $this->current_page+2; ?></a>
<?php
}
else
{
?>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->current_page+1); ?>"><?php echo $this->current_page+1; ?></a>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->current_page+2); ?>"><?php echo $this->current_page+2; ?></a>
<?php
}
}
}
public function currentEndPage3($showE3)
{
if($this->current_page == $this->total_pages - 3 && $showE3)
{
if($this->current_page == $this->current_page)
{
?>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->current_page-1); ?>"><?php echo $this->current_page-1; ?></a>
<span class='pagination-selected'><?php echo $this->current_page;?></span>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->current_page+1); ?>"><?php echo $this->current_page+1; ?></a>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->current_page+2); ?>"><?php echo $this->current_page+2; ?></a>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->current_page+3); ?>"><?php echo $this->current_page+3; ?></a>
<?php
}
else
{
?>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->current_page+1); ?>"><?php echo $this->current_page+1; ?></a>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->current_page+2); ?>"><?php echo $this->current_page+2; ?></a>
<?php
}
}
}
public function currentEndPage4($showE4)
{
if($this->current_page == $this->total_pages && $showE4)
{
if($this->current_page == $this->current_page)
{
?>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->current_page - 2); ?>"><?php echo $this->current_page - 2 ; ?></a>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->current_page - 1); ?>"><?php echo $this->current_page - 1; ?></a>
<span class='pagination-selected'><?php echo $this->current_page;?></span>
<?php
}
else
{
?>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->current_page+1); ?>"><?php echo $this->current_page+1; ?></a>
<a class='pagination-number' href="?<?php echo $this->get2Query($this->current_page+2); ?>"><?php echo $this->current_page+2; ?></a>
<?php
}
}
}
public function showStage6Paging()
{
?>
<!-- PREV -->
<?php if($this->hasPrev()) : ?>
<a class="pagination-number pagination-left" href="?<?php echo $this->get2Query($this->current_page - 1); ?>">< Previous</a>
<?php endif; ?>
<!-- END PREV -->
<?php
if($this->current_page == 1)
{
$this->currentStartPage1(true);
}
elseif($this->current_page == 2)
{
$this->currentStartPage2(true);
}
elseif($this->current_page == 3)
{
$this->currentStartPage3(true);
}
elseif($this->current_page == 4)
{
$this->currentStartPage4(true);
}
else
{
$this->showThreePagesStart(true);
if($this->current_page == $this->total_pages - 1)
{
$this->currentEndPage1(true);
}
elseif($this->current_page == $this->total_pages - 2)
{
$this->currentEndPage2(true);
}
elseif($this->current_page == $this->total_pages - 3)
{
$this->currentEndPage3(true);
}
elseif($this->current_page == $this->total_pages)
{
$this->currentEndPage4(true);
}
if(!$this->isBegin()) : ?>
<!-- BEGIN -->
<span class='pagination-break'>...</span>
<!-- END BEGIN -->
<?php endif;
for($this->minMax($i, $j); $i <= $j; $i++) : ?>
<?php if($this->current_page == $i) : ?>
<span class='pagination-selected'><?php echo $i; ?></span>
<?php else : ?>
<a class='pagination-number' href="?<?php echo $this->get2Query($i); ?>"><?php echo $i; ?></a>
<?php endif; ?>
<?php endfor;
if(!$this->isEnd()) : ?>
<!-- END -->
<span class='pagination-break'>...</span>
<!-- END END -->
<?php endif; ?>
<!-- NEXT -->
<?php if($this->hasNext()) : ?>
<a class='pagination-number pagination-right' href="?<?php echo $this->get2Query($this->current_page + 1); ?>">Next ></a>
<?php endif;?>
<!-- END NEXT -->
<?php
}
}
public function isFirst() { return $this->current_page ==1; }
public function isLast() { return $this->current_page == $this->total_pages; }
public function isBegin() {
return $this->current_page <= $this->interval + $this->residu;
}
public function isEnd() {
return $this->current_page > $this->total_pages - $this->interval;
#return $this->current_page > $this->total_pages - ($this->interval + $this->residu);
}
public function hasPrev() { return $this->current_page > 1; }
public function hasNext() { return $this->current_page < $this->total_pages; }
public function get2Query($link, $key = 'page') {
$get = $_GET;
$get[$key] = $link;
return http_build_query($get);
}
public function setRange($range) {
$this->range = (int) $range;
$this->interval = floor($this->range / 2);
$this->residu = $this->range % 2;
}
public function multi()
{
echo "<pre>";
echo "Ausgabe min: ".($this->current_page - $this->interval);
echo "\n";
echo "Ausgabe max: ".($this->current_page + $this->interval);
echo "\n";
echo "Ausgabe current: ".$this->current_page;
echo "\n";
echo "Ausgabe total_pages: ".$this->total_pages;
echo "\n";
echo "Ausgabe isBegin: ".($this->interval + $this->residu);
echo "</pre>";
}
public function minMax(&$min, &$max) {
$min = $this->current_page - $this->interval;
$max = $this->current_page + $this->interval;
if($this->range % 2 == 0)
$this->current_page < ($this->total_pages / 2) ? $min++ : $max--;
if($min < 1) {
$max -= $min - 1;
$min = 1;
$max < $this->total_pages or $max = $this->total_pages;
} elseif($max > $this->total_pages) {
$min -= $max - $this->total_pages;
$max = $this->total_pages;
$min >= 1 or $min = 1;
}
}
}
?>
Stylesheet
style.css
HTML:
body {
margin: 0px;
background: #000000;
font: 12px "Trebuchet MS", Verdana, Sans-serif;
color: #E5E5E5;
}
a {
color: #88d9f3;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
/* Pagination */
.pagination {
text-align: center;
display: block;
padding: 5px 0px;
}
a.pagination-number {
background: #000;
padding: 2px 7px 2px 7px;
border: 1px solid #383937;
margin: 0px 5px;
}
a.pagination-number:hover {
color:#000;
background-color: #89d9fc;
text-decoration: none;
}
.pagination-selected {
color: #888;
background: #000;
padding: 2px 7px 2px 7px;
border: 1px solid #888;
margin: 0px 5px;
height: 40px;
}
.pagination-break {
padding: 0px 5px;
}
Mysql Controller
controller.php
PHP:
<?php
require_once __DIR__.'/include/paginate.php';
$get_input = array_change_key_case($_GET, CASE_LOWER);
$page = isset($get_input['page']) ? $get_input['page'] : 1;
$pagin = new Paginate($page, 10,3, false);
$db = @new MySQLi('localhost', 'root', '', 'db_01');
$db->connect_errno and die('Connect Failed : '.$db->connect_error);
$res = $db->query('SELECT COUNT(*) FROM video');
$total = $res->fetch_row();
$pagin->setTotal($total[0]);
$res->close();
$sql = 'SELECT * FROM video';
$sql .= ' LIMIT '.$pagin->limit;
$sql .= ' OFFSET '.$pagin->offset;
if(!$res = $db->query($sql)) {
echo 'Query failed : '.$db->error.'<br />';
echo 'sql : '.$sql;
} else {
while($row = $res->fetch_assoc()) {
$pagin->data[] = $row;
}
$res->close();
}
$db->close();
?>
Hier die Archiv seiten mit dem paging
http://web.archive.org/web/20071006111945/stage6.divx.com/videos/
http://web.archive.org/web/20071006211014/stage6.divx.com/videos/?page=2
http://web.archive.org/web/20071006222143/stage6.divx.com/videos/?page=3
http://web.archive.org/web/20071011004309/stage6.divx.com/videos/?page=4
http://web.archive.org/web/20071011004315/stage6.divx.com/videos/?page=5
Ich würde auch die arbeit bezahlen...
Zuletzt bearbeitet: