-2

我想问我如何隐藏结果页面上的一些页码,以便它们显示如下:

[First] [Back] [1] [2] [3] [4] [5] ..... [10] [11] [12] [13] [14] [15] [Next] [Show Last]

现在它显示如下:

[1] [2] [3] [4] [5] [6] [7] [8] [8] [10] [11] [12] [13] [14] [15]

但我不想要那个。我想让它们像第一个例子一样显示。

这是我用于在页面中生成结果的代码:

<?PHP
$requested_page = isset($_GET['page']) ? intval($_GET['page']) : 1;

// Get the product count
$r = mysql_query("SELECT COUNT(*) FROM `oferts`");
$d = mysql_fetch_row($r);
$product_count = $d[0];

$products_per_page = 20;

// 55 products => $page_count = 3
$page_count = ceil($product_count / $products_per_page);

// You can check if $requested_page is > to $page_count OR < 1,
// and redirect to the page one.

$first_product_shown = ($requested_page - 1) * $products_per_page;



// Then we retrieve the data for this requested page
$r = mysql_query("SELECT * FROM `oferts` ORDER BY id DESC LIMIT $first_product_shown, $products_per_page ");

    while($rowi = mysql_fetch_array($r))
                {
                $title = addslashes($rowi['title']);
                $fromweb = addslashes($rowi['fromweb']);
                $image = addslashes($rowi['image']);
                $link = addslashes($rowi['link']);
                $price = addslashes($rowi['price']);
                $realprice = addslashes($rowi['realprice']);
                $endDate = addslashes($rowi['endDate']);
                $calc = $realprice / $price;
                if ($realprice == 0)
                {
                $procent = 0;
                }
                if ($realprice != 0)
                {
                $percent = 100/$calc;
                $reshenie = 100-$percent;
                $procent = substr($reshenie,0,2);
                }
                if ($fromweb == '1') {
                $divname = "ozo";
                }
                if ($fromweb == '2') {
                $divname = "vip";
                }               
                $seconds = strtotime("$endDate") - time();

                $days = floor($seconds / 86400);
                $seconds %= 86400;

                $hours = floor($seconds / 3600);
                $seconds %= 3600;

                $minutes = floor($seconds / 60);
                $seconds %= 60;

                $position=65;
                $titleNumbered = mb_substr($title, 0, $position, "utf-8");

                $healthy = array('\"');
                $yummy   = array('');

                $TitleText = str_replace($healthy, $yummy, $titleNumbered);
                ?>
<div class="OfferBox">
<center>
    <div class="<?PHP echo $divname;?>"></div>
    <a href="<?PHP echo $link;?>" target="_blank"><img src="<?PHP echo $image;?>" style="width:190px;border:1px solid #E5E5E5;"/></a>
    <div class="OfferText"><?PHP echo "$TitleText...";?></div>
    <div class="p1"><b><?PHP echo $realprice;?>лв.</b></div><div class="p2"><b>-<?PHP echo $procent;?>%</b></div><div class="p3"><b><?PHP echo $price;?>лв.</b></div>
    <a href="<?PHP echo $link;?>" class="OfferButton" target="_blank"></a>
    <div class="timeleft">Изтича след:<br><?PHP echo "$days дни | $hours часа | $minutes мин.";?></div>
</center>   
</div>
<?PHP
}
?>
</div>
<?PHP
echo '<div style="clear:both;display:block;bottom:0;float:right;margin-right:20px;">';
for($i=1; $i<=$page_count; $i++) {
    if($i == $requested_page) {
        echo "<span class='pagenumberSelected'><b>$i</b></span> ";
    } else {
        echo '<a href="index.php?page='.$i.'" class="pagenumber"><b>'.$i.'</b></a> ';
    }
}
echo '</div><br>';
?>

那我怎么做呢?当它们更多时,我如何隐藏一些页码?

4

2 回答 2

0

这是相关的代码和平:

<?php
for($i=1; $i<=$page_count; $i++) {
    if($i == $requested_page) {
        echo "<span class='pagenumberSelected'><b>$i</b></span> ";
    } else {
        echo '<a href="index.php?page='.$i.'" class="pagenumber"><b>'.$i.'</b></a> ';
    }
}
?>

有 3 个变量很重要:$i、$page_count 和 $requested_pa​​ge

  • $i = 迭代器
  • $page_count = 总页数
  • $requested_pa​​ge = 已加载的页面

在伪代码中

if $page_count > 10
  show if $i < 3
  show if $i = $requested_page -1
  show if $i = $requested_page
  show if $i = $requested_page +1    
  show if $i > $page_count - 3
于 2013-08-09T13:10:27.853 回答
-1

这是一个示例,如何仅显示最后 10 页而不是当前页之前的每一页:

for($i=$page_count-10; $i<=$page_count; $i++) {
    if($i == $requested_page) {
        echo "<span class='pagenumberSelected'><b>$i</b></span> ";
    } else {
        echo '<a href="index.php?page='.$i.'" class="pagenumber"><b>'.$i.'</b></a> ';
    }
}
于 2013-08-09T12:49:14.997 回答