darknessmdk Posted September 18, 2007 Share Posted September 18, 2007 I found this class on the net, It breaks results of a query up into pages I however know nothing of classes and have no idea how to implement this into my code The class is <?php class Pagination { public $curPage; public $totalItems; public $itemsPerPage; public $urlPrefix; public $pageCount; public $links; public $cutOff; function __construct( $curPage , $totalItems , $itemsPerPage , $urlPrefix ){ $this->curPage = $curPage; $this->totalItems = $totalItems; $this->itemsPerPage = $itemsPerPage; $this->urlPrefix = $urlPrefix; if( $this->totalItems > $this->itemsPerPage ) $this->init( ); } private function wrapInContainer( $what ){ echo '<div class="pagination">'.$what.'</div>'; } private function init( ){ //global $SETTINGS; $this->links = array( ); $this->cutOff = 4;//$SETTINGS->get( 'PAGINATION_CUTOFF' ); $this->pageCount = ceil( $this->totalItems / $this->itemsPerPage ); if( $this->curPage > 1 ){ $links[] = '<a href="'.$this->urlPrefix.'&p='.( $this->curPage - 1 ).'">< Previous</a>'; } for( $i = 1; $i <= $this->pageCount ; $i++ ){ if( ( $i > ( $this->cutOff + 1 ) && $i < ( $this->curPage - $this->cutOff ) ) || ( $i > ( $this->curPage + $this->cutOff ) && $i < ( $this->pageCount - $this->cutOff ) ) ){ $links[] = '.'; } else { if( $i == $this->curPage ){ $links[] = '<b>'.$i.'</b>'; } else { $links[] = '<a href="'.$this->urlPrefix.'&p='.$i.'">'.$i.'</a>'; } } } $imploded = implode( ',' , $links ); $imploded = preg_replace( '/(\.,)+/' , '...,' , $imploded ); $links = explode( ',' , $imploded ); if( $this->curPage < $this->pageCount ){ $links[] = '<a href="'.$this->urlPrefix.'&p='.( $this->curPage + 1 ).'">Next ></a>'; } $output = implode( ' ' , $links ); $this->wrapInContainer( $output ); } } ?> my code is <?PHP //Search Results // $priceresult = mysql_query("SELECT price FROM properties"); // echo $state; $query_count = "SELECT * FROM gallery"; $result_count = mysql_query($query_count); $totalrows = mysql_num_rows($result_count); if(empty($page)){ $page = 1; } $pages = ceil($totalrows / $limit); $limitvalue = $page * $limit - ($limit); $query_order = " LIMIT $limitvalue, $limit"; $query = $query_count."".$query_order ; //echo $query_count; $result = mysql_query($query) or die("Error: " . mysql_error()); //$row=mysql_fetch_array($result); $countrows = mysql_num_rows($result); if($countrows == NULL) { echo ("No images currently uploaded"); // echo ("<center>There are currently no listings</center>"); } else { echo ("<table border='0' cellspacing='0' cellpadding='5' align='center'>"); if($result && mysql_num_rows($result) > 0) { $i = 0; $max_columns = 3; while($row = mysql_fetch_array($result)) { // make the variables easy to deal with extract($row); // open row if counter is zero if($i == 0){ echo "<tr>"; } echo ("<td align='center'><a href=\"javascript:openwindow('$row[image]',500,375,600,525,'The Better Basement Company')\" class=\"linkcolor\"><img src='$row[image]' width='182' height='124' border='1' class=\"linkcolor\" /></a></td>"); // increment counter - if counter = max columns, reset counter and close row if(++$i == $max_columns) { echo "</tr>"; $i=0; } // end if } // end while } // end if results // clean up table if($i < $max_columns) { for($j=$i; $j<$max_columns;$j++) echo ""; } echo ("</table>"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/69763-implementing-a-class/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.