PagedQuery.php

Go to the documentation of this file.
00001 <?php 00002 00003 /* 00004 * $Id: PagedQuery.php,v 1.1 2004/05/21 10:28:21 micha Exp $ 00005 * 00006 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00007 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00008 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00009 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00010 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00011 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00012 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00013 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00014 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00015 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00016 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00017 * 00018 * This software consists of voluntary contributions made by many individuals 00019 * and is licensed under the LGPL. For more information please see 00020 * <http://creole.phpdb.org>. 00021 */ 00022 00023 require_once 'jargon/Query.php'; 00024 00036 class PagedQuery extends Query 00037 { 00039 var $page; 00040 00046 function PagedQuery(/*Connection*/ &$conn, $sql = null, $page = 1, $rowsPerPage = 25) 00047 { 00048 /* parent checks connection type */ 00049 parent::Query($conn, $sql); 00050 $this->setRowsPerPage($rowsPerPage); 00051 $this->setPage($page); 00052 } 00053 00059 function setPage($p) 00060 { 00061 $this->page = $page; 00062 // (re-)calculate start rec 00063 $this->calculateStart(); 00064 } 00065 00070 function getPage() 00071 { 00072 return $this->page; 00073 } 00074 00079 function setRowsPerPage($r) 00080 { 00081 $this->max = $r; 00082 // (re-)calculate start rec 00083 $this->calculateStart(); 00084 } 00085 00090 function getRowsPerPage() 00091 { 00092 return $this->max; 00093 } 00094 00100 function calculateStart() 00101 { 00102 $this->start = ( ($this->page - 1) * $this->max ); 00103 } 00104 00115 function getTotalRecordCount() 00116 { 00117 $stmt =& $this->conn->createStatement(); 00118 $rs =& $stmt->executeQuery($this->sql); 00119 00120 if (Creole::isError($rs)) { 00121 return $rs; 00122 } 00123 00124 return $rs->getRecordCount(); 00125 } 00126 00127 } 00128

This file is part of the Creole[php4] library.


Copyright © 2004 Hans Lellelid  
Creole[php4] CVS