Php multi-table query and paging implementation

Source: Internet
Author: User
{Code...} uses tp framework SQL to display 5 pieces of data by page, for example, by page. how can this problem be solved?
Public function my_join_activity () {header ('content-type: text/html; charset = utf-8 '); $ Model = M (); $ unionid = session ('unionid '); if (! $ Unionid) {$ inde = A ('index'); $ inde-> login ();} // use native SQL for multi-table queries note the and statement of the where Condition $ list = $ Model-> query ("select * from activity, apply where apply. ac_id = activity. ac_id and apply. unionid = '{$ unionid} 'Order by ap_id desc "); $ this-> assign ('list', $ list); $ this-> display ();}

In tp framework SQL, how does one display 5 pieces of data by page?

Reply content:
Public function my_join_activity () {header ('content-type: text/html; charset = utf-8 '); $ Model = M (); $ unionid = session ('unionid '); if (! $ Unionid) {$ inde = A ('index'); $ inde-> login ();} // use native SQL for multi-table queries note the and statement of the where Condition $ list = $ Model-> query ("select * from activity, apply where apply. ac_id = activity. ac_id and apply. unionid = '{$ unionid} 'Order by ap_id desc "); $ this-> assign ('list', $ list); $ this-> display ();}

In tp framework SQL, how does one display 5 pieces of data by page?

Use count and limit

$ User = M ('user'); // instantiate the User object $ count = $ User-> where ('status = 1')-> count (); // query the total number of records meeting the requirements $ Page = new \ Think \ Page ($ count, 25 ); // The total number of incoming records and the number of records displayed on each Page (25) $ show = $ Page-> show (); // Display output by Page // query paging data. Note that the parameters of the limit method must use the attribute $ list = $ User-> where ('status = 1') of the Page class ') -> order ('create _ time')-> limit ($ Page-> firstRow. ','. $ Page-> listRows)-> select (); $ this-> assign ('list', $ list); // assign a dataset $ this-> assign ('page ', $ show); // value-assigned paging output $ this-> display (); // output Template
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.