获取致命错误:在第33行的C:\ wamp \ www \ quotes \ paginator.php中的非对象上调用成员函数_query()

时间:2015-07-30 13:29:09

标签: php mysqli

我阅读了给我的参考资料并从代码中获取了帮助但是我得到了致命的错误。如上所述。请查看我的代码并告诉我在哪里。 我有两页。 index.php和paginator.php 为什么我得到致命错误我无法理解。

的index.php

      <?php

     class Paginator {

    private $_con;
    private $_limit;
    private $_page;
    private $_query;
    private $_total;


  public function _construct( $con, $query ) 
 {

 $this->_con = $con;
 $this->_query = $query;

 $rs= $this->_con->query( $this->_query );
 $this->_total = $rs->num_rows;

 }

 public function getData( $limit = 10, $page = 1 ) {

$this->_limit   = $limit;
$this->_page    = $page;

 if ( $this->_limit == 'all' ) {
    $query      = $this->_query;
 } else {
    $query      = $this->_query . " LIMIT " . ( ( $this->_page - 1 ) *     $this->_limit ) . ", $this->_limit";
  }
  $rs             = $this->_conn->query( $query );

    while ( $row = $rs->fetch_assoc() ) {
    $results[]  = $row;
    }

    $result         = new stdClass();
    $result->page   = $this->_page;
    $result->limit  = $this->_limit;
    $result->total  = $this->_total;
    $result->data   = $results;

    return $result;
    }  

  public function createLinks( $links, $list_class ) {
   if ( $this->_limit == 'all' ) {
    return '';
    }

   $last       = ceil( $this->_total / $this->_limit );

   $start      = ( ( $this->_page - $links ) > 0 ) ? $this->_page - $links :   1;
  $end        = ( ( $this->_page + $links ) < $last ) ? $this->_page +   $links : $last;

  $html       = '<ul class="' . $list_class . '">';

    $class      = ( $this->_page == 1 ) ? "disabled" : "";
    $html       .= '<li class="' . $class . '"><a href="?limit=' . $this->_limit . '&page=' . ( $this->_page - 1 ) . '">&laquo;</a></li>';

    if ( $start > 1 ) {
    $html   .= '<li><a href="?limit=' . $this->_limit . '&page=1">1</a>  </li>';
     $html   .= '<li class="disabled"><span>...</span></li>';
     }

    for ( $i = $start ; $i <= $end; $i++ ) {
    $class  = ( $this->_page == $i ) ? "active" : "";
    $html   .= '<li class="' . $class . '"><a href="?limit=' . $this->_limit  .     '&page=' . $i . '">' . $i . '</a></li>';
  }

    if ( $end < $last ) {
    $html   .= '<li class="disabled"><span>...</span></li>';
    $html   .= '<li><a href="?limit=' . $this->_limit . '&page=' . $last .  '">' . $last . '</a></li>';
   }

 $class      = ( $this->_page == $last ) ? "disabled" : "";
 $html       .= '<li class="' . $class . '"><a href="?limit=' . $this- >_limit . '&page=' . ( $this->_page + 1 ) . '">&raquo;</a></li>';

  $html       .= '</ul>';

  return $html;
  }
  }
  ?>                

paginator.php

<?php
$currentdate = date('m/d/Y');
echo "The Current Date is: $currentdate";
?>

2 个答案:

答案 0 :(得分:1)

首先尝试用mysql解决这个基本问题:)

限制和抵消将是你的朋友

答案 1 :(得分:0)

研究linke我给了你,如果你有任何问题,请回到这篇文章,我会编辑我的答案给你发回信。

Here you got all info you need to do that

解决问题的步骤:

Select all data from given Mysql Table.

Fetch selected data, to get it ready for use.

Throw it into the User Interface with for example loop.

Do Pagination to split your data across X-number of pages.

您必须将您的函数(方法)放在类中,例如:

class Pagination {

function getData(){
}

}

同样构造有两个__ not _:

class Pagination {

   // properties go here

   public function __construct()
   {
   }

   public function getData()
   {
   }
}

要调用函数,您必须创建新的类对象:

$pagination = new Pagination;

然后你可以调用方法:

$pagination->getData();

您应首先阅读/观看有关PHP OOP的内容并了解基础知识: some php oop tutorials