Simple use of select lookup in ZF framework Db & pagination

Source: Internet
Author: User
Job exercise ZendFramework? Php * How to Use the queryer * isset ($ _ GET [page])? $ Page $ _ GET [page]: $ page1; introduces the Loader class (automatic loading class) require_once (ZendLoader. php); Use the Loader class to introduce a Db class Zend_Loader: loadClass (Zend_Db); Introduce the Zend_Db format

Job exercise Zend Framework? Php/* How to Use the queryer */isset ($ _ GET ['page'])? $ Page = $ _ GET ['page']: $ page = 1; // introduces the Loader class (automatic loading class) require_once ("Zend/Loader. php "); // use the Loader class to introduce a Db class Zend_Loader: loadClass (" Zend_Db "); // introduce the Zend_Db format

Job exercise Zend 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"
";?>

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.