使用分页从数据库中抽取编号结果- PHP



我正在为我正在设计的一个网站创建一个脚本,该脚本将使用分页从数据库中提取引号,

我已经很好地完成了这部分,设置分页类并实际使其打印出结果,但我一直试图使其使用编号系统打印-就像每个一样。

我希望每个引用都有自己的编号,如:

  1. "一个人不能超越他的影子";
  2. "foo不是傻瓜,只是在php中使用"
  3. "so on and so forth";

    看我的课:

    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

    我让他们按顺序列出页:11[quote]滚石不生苔。[/quote]
    滚石不生苔。[/quote]
    [quote]滚石不生苔。[/quote]
    滚石不生苔。[/quote]
    5[quote]滚石不生苔。[/quote]

    但是另一个页面quote.html?p=2 而不是从开始第2页:6 (qoute)没有[/quote]滚石不生苔。[/quote]

    rather重新开始从1开始计数页:11 (qoute)没有[/quote][quote]滚石不生苔。[/quote]

    我希望它看起来像我们在BBC足球博客评论2页从101开始而不是从1重新开始

    我希望我的问题不会太长而无法理解,如果我很抱歉,只是想把它们都贴出来以便更好地理解。

我想你可能把问题复杂化了。一些伪代码:

Current number = Number of items per page * Current page number

Current page number来自您的URL,带有?p= GET参数。

然后在每次迭代中回显一个引号,给Current number加一个。

最新更新