Source code implementation of the paging function provided by Ecmall. In the secondary development of Ecmall, paging is essential. This system already comes with the paging function. let's take a look at how to use this page. The following is a custom class, which is used in the secondary development of Ecmall. paging is essential. This system already comes with the paging function. let's take a look at how to use this page.
The following is a custom class used to view the order details. The key lies in the get_order_data () method, and the use of paging is also within this method. All the comments are available, so it is easier to understand.
_ Get_page (NUM_PER_PAGE); $ page ['item _ count'] = $ stats ['total _ count']; $ this-> _ format_page ($ page ); $ this-> assign ('page _ info', $ page); $ this-> display('gorder.index.html ');}/* order record */function orderslog () {$ goods_id = empty ($ _ GET ['id'])? 0: intval ($ _ GET ['id']); if (! $ Goods_id) {$ this-> show_warning ('hacking attempt'); return;} $ data = $ this-> get_order_data ($ goods_id ); if ($ data = false) {return;} $ this-> assign ('order', $ data); $ this-> display('gorder.index.html ');} function get_order_data ($ goods_id) {// clean_cache (); $ cache_server = & cache_server (); // print_r ($ cache_server); $ key = 'Order _'. $ goods_id; // $ key = $ this-> _ get_cache_id (); $ r = $ cache_server-> get ($ ke Y); $ cached = true; $ db = & db (); $ SQL = "select count (*) from shop_order a, shop_order_extm B, shop_order_goods cwhere. order_id = B. order_id and B. order_id = c. order_idand c. goods_id = '". $ goods_id. "'and. status! = '11' and a. status! = '0' and a. status! = '20' order by. add_time desc "; // echo $ SQL; $ num = $ db-> getone ($ SQL ); // obtain the total number of records $ page = $ this-> _ get_page (NUM_PER_PAGE); // The number of records displayed on each page, the default value is 10. $ page ['item _ count'] = $ num; // An Array $ page is returned, $ page ['limit'] = 0, 10 $ this-> _ format_page ($ page); // format the page $ sql2 = "select. order_id,. buyer_name,. add_time,. status, B. phone_tel, B. phone_mob, B. consignee, c. price, c. quantity, c. goods_id from shop_order a, shop_order_extm B, Shop_order_goods cwhere a. order_id = B. order_id and B. order_id = c. order_idand c. goods_id = '". $ goods_id."' and a. status! = '11' and a. status! = '0' and a. status! = '20' order by. add_time desc limit ". $ page ['limit']; $ result = $ db-> query ($ sql2); $ this-> assign ('page _ info', $ page ); // pass the page number to the template page $ this-> assign ('que', $ sql2); // pass the query result to the template page // $ r = array (); while ($ myrow = $ db-> fetch_array ($ result) {$ r [] = $ myrow;} $ cache_server-> set ($ key, $ r, 1 ); return $ r ;}}?>
Simplified as follows:
Define ("LIMIT", 10); $ goods_mod = & db ('test'); // create an entity model (Operation table) $ count = 'SELECT count (id) from test'; $ num = $ goods_mod-> getone ($ count); // obtain the total number of records $ page = $ this-> _ get_page (LIMIT ); // The number of items displayed on each page. the default value is 10. $ page ['item _ count'] = $ num; // An Array $ page is returned, $ page ['limit'] = 0, 10 $ this-> _ format_page ($ page); // format the page $ SQL = 'SELECT id, title, content from test order by id desc limit '. $ page ['limit']; $ que = $ goods_mod-> getAll ($ SQL); // query record $ this-> assign ('page _ info ', $ page); // pass the page number to the template page $ this-> assign ('que', $ que); // pass the query result to the template page
Bytes. This system already comes with the paging function. let's take a look at how to use this page. The following is a custom class for query...