Zf framework db Class paging example sharing _ PHP Tutorial

Source: Internet
Author: User
Examples of the zf framework db class are shared by page. This article mainly introduces the paging example of the db Class of the zf framework. the code is very simple. let's take a look at the comments and use the following code as a paging example of the zf framework :? Phpisset ($ _ GET [page])? $ Pa This article mainly introduces the paging example of the zf framework db Class. the code is very simple. you can use it by taking a look at the annotations.

The following is a paging example code of the zf framework: '2017. 0.0.1 ', 'username' => 'root', 'password' => '000000', 'dbname' => 'test', 'filer' => "true "); // inform Zend_Db of the database and database configuration information operated by the Zend_Db class $ Db = Zend_Db: factory ('pdo _ mysql', $ Config ); // execute the encoding statement $ Db-> query ("set names utf8"); // ----------------------------------------------- // use fetchOne () method to get the Total number of tables $ Total = $ Db-> fetchOne ("select count (*) from gongsi"); // defines the number of entries displayed on each page $ B = 50; // obtain the Total number of pages $ A = ceil ($ Total/$ B ); // ----- perform the following operations for a series of queries, result sets, and pages: $ Select = $ Db-> select (); $ Select-> from ('sango ', array ('s _ sheng as province ', 'sum (s_gongzi) as total wage', 'min (s_gongzi) as minimum wage ', 'Max (s_gongzi) as highest wage ', 'avg (s_gongzi) as average wage '); // $ Select-> Where ('s _ gongzi> = 100 '); // $ Select-> Where ("s_sheng = 'hebei '"); // $ Select-> order ('s _ sheng asc '); // $ Select-> order ('s _ gongzi desc '); $ Select-> group ('s _ sheng '); // group // $ Select-> having ('maximum salary> 100'); // additional conditions $ Select-> order ('maximum salary desc '); // Sort $ Select-> limit (0, 0); // Intercept $ Select-> limitPage ($ page, $ B); // the page/* SQL statement is equivalent: select s_sheng as province, sum (s_gongzi) as highest salary from sanguo group by s_sheng having highest salary> 10000 order by highest salary desc limit; */$ Result = $ Db-> fetchAll ($ Select); echo" "; Echo" "; Foreach ($ Result as $ key => $ value) {echo" "; Foreach ($ value as $ key2 => $ value2) {echo" ";} Echo" ";} Echo" "; Echo" "; Echo" "; Echo"
Province Total salary Minimum wage Highest salary Average salary
". $ Value2 ."
"; Echo" homepage "; if ($ page> 1) {echo" previous page ";} for ($ I = 1; $ I <= 15; $ I ++) {echo "". $ I. "";} if ($ page <$ Total) {echo "next page";} echo "last page"; echo"
";?>

The following is a paging example code of the zf framework :? Phpisset ($ _ GET ['Page'])? $ Pa...

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.