[英]can't echo php class variable
我想編寫一個php簡單的分頁類。 這是我的代碼:
<?php
class Pagination {
public $rowsPerPage;
public $currentPage;
public $totalPages;
public $totalRows;
public $firstElement;
public $lastElement;
public function paginate()
{
if(isset($_GET['page'])){
$this->currentPage = $_GET['page'];
}
$this->totalPages = $this->totalRows/$this->rowsPerPage ;
return $this->totalPages;
$this->firstElement = $this->currentPage-1)*$this->rowsPerPage+1;
return $this->firstElement;
}
}
$totalRecords = 55;
$paginator = new Pagination();
$paginator->totalRows = $totalRecords;
$paginator->rowsPerPage = 5;
$paginator->paginate();
echo $paginator->totalPages;
echo $paginator->firstElement;
?>
我可以回顯$ paginator-> totalPages; 但不是$ paginator-> firstElement。 我做錯了什么? 謝謝
您的paginate
函數有兩個return
語句。
當代碼命中時, return $this->totalPages;
,它將停止運行該功能。 因此,永遠不會運行$this->firstElement = ...
行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.