Zebra_Pagination是一个通用的PHP类,用来根据记录数和每页显示数自动生成分页链接。
示例代码:
<?php//let'spaginatedatafromanarray...$countries=array(//arrayofcountries);//howmanyrecordsshouldbedisplayedonapage?$records_per_page=10;//includethepaginationclassrequire'path/to/Zebra_Pagination.php';//instantiatethepaginationobject$pagination=newZebra_Pagination();//thenumberoftotalrecordsisthenumberofrecordsinthearray$pagination->records(count($countries));//recordsperpage$pagination->records_per_page($records_per_page);//here'sthemagick:weneedtodisplay*only*therecordsforthecurrentpage$countries=array_slice($countries,(($pagination->get_page()-1)*$records_per_page),$records_per_page);?><table><tr><th>Country</th></tr><?phpforeach($countriesas$index=>$country):?><tr<?phpecho$index%2?'class="even"':'')?>><td><?phpecho$country?></td></tr><?phpendforeach?></table><?php//renderthepaginationlinks$pagination->render();?>
评论