Php paging usage (from yii Framework)
- Php; toolbar: false ">/* public function actionReport ()
- {
- $ SQL = "select * from {goods }}";
- $ Criteria = new CDbCriteria ();
- $ Result = Yii: app ()-> db-> createCommand ($ SQL)-> query ();
- $ Pages = new CPagination ($ result-> rowCount );
- $ Pages-> pageSize = 2;
- $ Pages-> applyLimit ($ criteria );
- $ Result = Yii: app ()-> db-> createCommand ($ SQL. "LIMIT: offset,: limit ");
- $ Result-> bindValue (': offset', $ pages-> currentPage * $ pages-> pageSize );
- $ Result-> bindValue (': limit', $ pages-> pageSize );
- $ GoodsInfo = $ result-> query ();
- $ This-> render ('index', array (
- 'Goodsinfo' => $ goodsInfo,
- 'Pages '=> $ pages,
- ));
- }*/
- Foreach ($ goodsInfo as $ v ){
- }
- ?>
- ?>
- // Pagination widget code:
- $ This-> widget ('clinkpager', array ('page' => $ pages ));
- ?>
Item name |
Price |
Update Time |
|
|
|
Method 2: Use your own paging class to complete paging 1. Controller code:
Public function actionIndex (){
- $ Goods_m = goods: model ();
// 1. obtain the total number of records for the product
- $ Cnt = $ goods_m-> count ();
// 2. instantiate a paging object
- $ Page = new Page ($ cnt, 2 );
// 3. re-assemble the SQL statement according to the paging style for query
- $ SQL = "select * from {goods} $ page-> limit ";
- $ GoodsInfo = $ goods_m-> findAllBySql ($ SQL );
// 4. obtain the page List (to be displayed in the view template)
- $ PageList = $ page-> fpage ();
$ This-> renderPartial ('index', array ('goodsinfo' => $ goodsInfo, 'pagelist' => $ pageList ));
- }
2. View code:
- Foreach ($ goodsInfo as $ v ){
- }
- ?>
- ?>
- Echo $ pageList;
- ?>
Item name |
Price |
Create_time |
|
|
|
-
The paging class should be placed in a directory that can be automatically loaded; |