листване на страниците

C++ JAVA
Post Reply
martinski
Нов
Нов
Posts: 26
Joined: Wed Dec 23, 2015 10:03 pm

листване на страниците

Post by martinski » Sat Feb 13, 2016 7:23 pm

Здравейте приятели,
от mysql когато изкарвам информация в table съм сложил код за листване,
който е

Code: Select all

<?php 
$sql = "SELECT COUNT&#40;id&#41; FROM offerts WHERE o1=2"; 
$rs_result = mysql_query&#40;$sql&#41;; 
$row = mysql_fetch_row&#40;$rs_result&#41;; 
$total_records = $row&#91;0&#93;; 
$total_pages = ceil&#40;$total_records / 2&#41;; 
  
for &#40;$i=1; $i<=$total_pages; $i++&#41; &#123; 
            echo "<a href='sell.php?page=".$i."'>".$i."</a> "; 
&#125;; 
?>
как трябва да проеменя кода за да стане този дизайн и функционалност

Code: Select all

<<  &#91;1&#93; 2 3 4 5 6 7 8 9 10 11 12 13 14 15  >>

User avatar
SVTerziev
Нов
Нов
Posts: 158
Joined: Fri Jul 13, 2012 12:32 am
Answers: 34

Post by SVTerziev » Sat Feb 13, 2016 11:24 pm

[php]$current = array_key_exists("page", $_GET) ? (int)$_GET['page'] : '1';

if ($current > 1) {
$prev = $current - 1;
echo '<a href="sell.php?page=' . $prev . '"><<</a> ';
}

for ($i = 1; $i <= $total_pages; $i++) {
if ($i == $current) {
echo "[ <a href='sell.php?page=".$i."'>".$i."</a> ] ";
continue;
}

echo "<a href='sell.php?page=".$i."'>".$i."</a> ";
}

if ($current < $total_pages) {
$next = $current + 1;
echo ' <a href="sell.php?page=' . $next . '">>></a>';
}[/php]

Post Reply