好吧我就是這樣,我對將使用分頁到了從數據庫中提取引號中的網站時的設計創建一個腳本,編號結果 - PHP
我已經做了一部分相當不錯,設置分頁課程並實際上將其打印出來,但我一直試圖使用編號系統進行打印 - 如每個系統一樣。
我希望每個報價都有自己的編號,如:
- 「一個人不能侵佔他的影子」;
- 「foo不是傻瓜,只是在php中使用」
「等等等等」;
看看我的等級:
class pagination extends cleanPost{ var $p=1, $max_r,$limits; var $count_all=0,$sql,$total,$table,$totalres,$totalpages; var $r,$i; var $show=10; function setMax($max_r){ $this->p = $this->clean($_GET['p']); $this->max_r = $max_r; if(empty($this->p)) { $this->p = 1; } $this->limits = ($this->p - 1) * $this->max_r; } function setData($table){ $this->table = $table; $this->sql = "SELECT * FROM ".$this->table." LIMIT ".$this->limits.",".$this->max_r.""; $this->sql = mysql_query($this->sql) or die(mysql_error()); $this->total = "SELECT * FROM ".$this->table.""; $this->totalres = mysql_query($this->total) or die(mysql_error()); $this->count_all = mysql_num_rows($this->totalres); // count all the rows $this->totalpages = ceil($this->count_all/$this->max_r); // work out total pages } function displayLinks($show){ $this->show = $show; // How many links to show echo "<br><br>"; if($this->p > 1) // If p > then one then give link to first page { $pagination .= "<div class=\"pagination\"> <a href=?p=1> [first] </a> "; } else { // else show nothing $pagination .= "<div class=\"pagination\">".""; } if($this->p != 1) { // if p aint equal to 1 then show previous text $previous = $this->p-1; $pagination .= "<a href=?p=$previous>«prev</a>"; } else { //else show nothing $pagination.= "<span class=\"disabled\">first</span>".""; } for($i =1; $i <= $this->show; $i++) // show ($show) links { if($this->p > $this->totalpages) { // if p is greater then totalpages then display nothing echo ""; } else if($_GET["p"] == $this->p) { //if p is equal to the current loop value then dont display that value as link $pagination .= $this->p ; } else{ $pagination .= " <a href=?p=".$this->p."> ".$this->p." </a>"; // else display the rest as links } $this->p++; //increment $p } if($_GET["p"] == $this->totalpages) {// if page is equal to totalpages then dont display the last page at the end of links $pagination.= "<span class=\"disabled\">last</span>".""; } else if($_GET["p"] != $this->totalpages) { // $pagination .= "..."; // display dots # $pagination .= "<a href=?p=".$this->totalpages."> ".$this->totalpages." </a>"; } else { // else display the last page link after other ones } if($_GET["p"] < $this->totalpages)// if p is less then total pages then show next link { $next = $_GET["p"] + 1; $pagination .= "<a href=?p=$next> next»</a>"; $pagination.= "<a href=?p=".$this->totalpages."> [last] </a>".""; } $pagination.= "</div>\n"; echo $pagination;
}
////////// ,這是我的報價顯示頁面
$page= new pagination; $page->setMax(5);//set the maximum quote shown per page $page ->setData("quotes"); $page ->display(); echo "<table border=1 width=100%>"; while ($row = mysql_fetch_array($page->sql)) { echo $num_results = mysql_num_rows($page->sql); echo "<tr>"; for ($i=0; $i <$num_results; $i++) { echo "<td>"; $num_found = $i + 1; echo $num_found.$row['ngwaquote']; echo "</td>"; } echo "</tr>"; } echo "</table><p>"; $page ->displayLinks(4) ;
結果我得到是,如果我點擊分頁鏈接中的第一個號碼 給我 quote.html?p = 1
我讓他們列出它連續 頁:1。 1 [報價]滾石不生苔了[/ quote]
2 [報價]滾石不生苔了[/ quote]
3 [引用]滾石沒有苔。[/報價]
4 [報價]滾石沒有苔。[/報價]
5 [報價]滾石沒有苔。[/報價]但是其他頁面quote.html?p = 2 而不是從開始 頁面:2 6 [qoute] nothing [/ quote] 0 。7 [報價]滾石沒有苔[/報價]
而開始從一個再次 頁面計數:1 1 [qoute]無[/報價] 2 [報價]滾石不長青苔。[/報價]
我希望它看起來像我們在BBC足球博客 這裏評論頁面數量從101 而不是開始從1遍2點再次開始
我希望我的問題是不是太長了解,如果我只是對不起f埃爾特喜歡張貼他們所有的更好的理解。
至少寫下一行代碼,它可能是非常好的開始從那裏,請? – Normal9ja
類似於'$ current_number = $ items_per_page *(int)$ _ GET ['p'];'? – Treffynnon