开发者社区> 问答> 正文

分页类调用后URL出错? 400 报错

分页类调用后URL出错? 400 报错

以下是内容也代码:该如何修改呢

错误信息是:Not Found

The requested URL /InputReactor.php&page=2 was not found on this server.

<?php
	$_mysqli = new mysqli('localhost','root','qwepoi','dq');  
	$_mysqli->set_charset('utf8');
	$sql = "SELECT * FROM question ";
	$result = $_mysqli->query($sql);
	include 'includes/page.class.php';
	$page = new Page($_total = $result->num_rows,1); 
	$limit = $page->limit;
	$sql = "SELECT * FROM question ".$limit;
	$result = $_mysqli->query($sql);
?>
<dl>
<?php while(!!$row = $result->fetch_assoc()){?>
<dt><?php echo $row['question_title'];?></dt>
<dd><?php echo $row['question_answer'];?></dd>
<?php }	?>	
</dl>
<?php echo $page->showpage();?>

下面是分页类代码

<?php  
    class Page {  
          private $total;      //总记录  
          private $pagesize;    //每页显示多少条  
          private $limit;          //limit  
          private $page;           //当前页码  
          private $pagenum;      //总页码  
          private $url;           //地址  
          private $bothnum;      //两边保持数字分页的量  
    
      //构造方法初始化  
      public function __construct($_total, $_pagesize) {  
         $this->total = $_total ? $_total : 1;  
         $this->pagesize = $_pagesize;  
         $this->pagenum = ceil($this->total / $this->pagesize);  
         $this->page = $this->setPage();  
         $this->limit = "LIMIT ".($this->page-1)*$this->pagesize.",$this->pagesize";  
         $this->url = $this->setUrl();  
         $this->bothnum = 1;  
      }  
    
      //拦截器  
      private function __get($_key) {  
         return $this->$_key;  
      }  
    
      //获取当前页码  
      private function setPage() {  
         if (!empty($_GET['page'])) {  
                if ($_GET['page'] > 0) {  //如果页码大于1
                   if ($_GET['page'] > $this->pagenum) {  //意思是如果得到的页码数大于总页码数则跳到最后一页。
                          return $this->pagenum;  
                   } else {  
                          return $_GET['page'];  //意思是如果得到的页码数小于或等于总页码数则跳至要去的页码。
                   }  
                } else {  //如果页码数小于1则跳到第一页
                   return 1;  
                }  
         } else {  
                return 1;  
         }  
      }   
    
    //获取地址  
      private function setUrl() {  
         $_url = $_SERVER["REQUEST_URI"];  
         $_par = parse_url($_url);  
         if (isset($_par['query'])) {  
                parse_str($_par['query'],$_query);  
                unset($_query['page']);  
                $_url = $_par['path'].'?'.http_build_query($_query);  
         }  
         return $_url;  
      }
         
    //数字目录  
      private function pageList() {  
         for ($i=$this->bothnum;$i>=1;$i--) {  
            $_page = $this->page-$i;  
            if ($_page < 1) continue;  
                $_pagelist .= ' <a ';  
         }  
         $_pagelist .= ' <span class="me">'.$this->page.'</span> ';  
         for ($i=1;$i<=$this->bothnum;$i++) {  
            $_page = $this->page+$i;  
                if ($_page > $this->pagenum) break;  
                $_pagelist .= ' <a ';  
         }  
         return $_pagelist;  
      }
    
    //首页  
      private function first() {  
         if ($this->page > $this->bothnum+1) {  
                return ' <a ...';  
         }  
      }  
    
      //上一页  
      private function prev() {  
         if ($this->page == 1) {  
                return '<span class="disabled">上一页</span>';  
         }  
         return ' <a ';  
      }  
    
      //下一页  
      private function next() {  
         if ($this->page == $this->pagenum) {  
                return '<span class="disabled">下一页</span>';  
         }  
         return ' <a ';  
      }  
    
      //尾页  
      private function last() {  
         if ($this->pagenum - $this->page > $this->bothnum) {  
                return ' ...<a ';  
         }  
      }    
      //分页信息  
      public function showpage() {  
         $_page .= $this->first();  
         $_page .= $this->prev();
         $_page .= $this->pageList();  
         $_page .= $this->next(); 
         $_page .= $this->last();  
		 return $_page;  
      }  
 }  
?>

展开
收起
爱吃鱼的程序员 2020-06-02 11:56:30 474 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    你的连接有问题 

    /InputReactor.php&page=2 

    你试一下 /InputReactor.php?page=2

    2020-06-02 11:56:43
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载