2010-05-10 71 views
4

自从我更新我的网页分页后,我试图添加FirstLast链接到我的分页以及...当搜索结果很长时。例如,我试图在下面的示例中实现以下内容。有人能帮我修复我的代码,以便我可以更新我的网站。谢谢PHP&MySQL分页更新帮助

First Previous 1 2 3 4 5 6 7 ... 199 200 Next Last 

我目前有以下显示使用我的代码。

Previous 1 2 3 4 5 6 7 Next 

这是显示链接的分页代码的一部分。

if ($pages > 1) { 

    echo '<br /><p>'; 

    $current_page = ($start/$display) + 1; 

    if ($current_page != 1) { 
     echo '<a href="index.php?s=' . ($start - $display) . '&p=' . $pages . '">Previous</a> '; 
    } 

    for ($i = 1; $i <= $pages; $i++) { 
     if ($i != $current_page) { 
      echo '<a href="index.php?s=' . (($display * ($i - 1))) . '&p=' . $pages . '">' . $i . '</a> '; 
     } else { 
      echo '<span>' . $i . '</span> '; 
     } 
    } 

    if ($current_page != $pages) { 
     echo '<a href="index.php?s=' . ($start + $display) . '&p=' . $pages . '">Next</a>'; 
    } 

    echo '</p>'; 

} 
+0

你能更具体,你的问题是什么? – awgy 2010-05-11 03:10:42

回答

0

刚刚获得总走回头路和:

$result_count = 200; // hypothetical 

// run your regular code..... 

$end_pages_to_display = 3; 

for($i = $result_count; $i <= ($result_count - $end_pages_to_display); $i--) 
{ 
    echo "<a href='index.php?page={$i}'>{$i}</a>"; 
} 

我的意思是......这不是那将适合您的网站的代码,但它是完全一样的逻辑。

0

我不确定你的''和'p'$ _GET变量是用于(盐和胡椒粉?),所以我只是使用'p',页面。

<?php 
$max = '20'; 
if ($pages > 1) { 

    echo '<br /><p>'; 

    $current_page = ($start/$display) + 1; 

    //add this here... first will always be one 
     echo '<a href="index.php?p=1">First</a>'; 
    if ($current_page != 1) { 
     echo '<a href="index.php?s=' . ($start - $display) . '&p=' . $pages . '">Previous</a> '; 
    } 

    for ($i = 1; $i <= $pages; $i++) { 
     if ($i != $current_page) { 
      echo '<a href="index.php?s=' . (($display * ($i - 1))) . '&p=' . $pages . '">' . $i . '</a> '; 
     } else { 
      echo '<span>' . $i . '</span> '; 
     } 
     // add this here... 
     if ($i == $max){ 
      // stop the for() loop 
      break; 
     // not so fancy way of displaying last two pages, use other example if you want to get fancy. 
     echo '<a href="index.php?p=' . ($pages - 1) . '">'.($pages - 1).'</a> '; 
     echo '<a href="index.php?p=' . ($pages) . '">'.($pages).'</a> '; 

     } 
    } 

    if ($current_page != $pages) { 
     echo '<a href="index.php?s=' . ($start + $display) . '&p=' . $pages . '">Next</a>'; 
    } 
     echo '<a href="index.php?p=1">Last</a>'; 
    echo '</p>'; 

} 
?>