This article mainly introduces the paging example of the db Class of the zf framework. the code is very simple. you can use the paging example of the zf framework by taking a look at the annotations.
The code is as follows:
Isset ($ _ GET ['Page'])? $ Page = $ _ GET ['Page']: $ page = 1;
// Introduce 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 status server
Zend_Loader: loadClass ("Zend_Db_Statement_Pdo ");
// Configure database connection information
$ Config = array ('host' => '2017. 0.0.1 ',
'Username' => 'root ',
'Password' => '123 ',
'Dbname' => 'test ',
'Filer' => "true"
);
// Inform Zend_Db of the database and database configuration information operated by the class
$ Db = Zend_Db: factory ('pdo _ mysql', $ Config );
// Execute the encoding statement
$ Db-> query ("set names utf8 ");
//-----------------------------------------------
// Use the fetchOne () method to obtain the total number of tables
$ Total = $ Db-> fetchOne ("select count (*) from gongsi ");
// Define the number of entries displayed per page
$ B = 50;
// Obtain the total number of pages
$ A = ceil ($ Total/$ B );
// ----- Next, perform a series of operations such as table query, result set fetch, and paging.
$ Select = $ Db-> select ();
$ Select-> from ('sanguo ', array ('s _ sheng as province', 'sum (s_gongzi) as total wage ', 'min (s_gongzi) as minimum wage ', 'Max (s_gongzi) as highest pay', 'avg (s_gongzi) as average pay '));
// $ Select-> Where ('s _ gongzi> = 3000 ');
// $ 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 ('highest salary desc '); // sort
$ Select-> limit (0, 0); // Intercept
$ Select-> limitPage ($ page, $ B); // page
/* The 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"
Province |
Total salary |
Minimum wage |
Highest salary |
Average salary |
";Foreach ($ Result as $ key => $ value){Echo"
";Foreach ($ value as $ key2 => $ value2){Echo"
". $ Value2 ." | ";}Echo"
";}Echo"
";Echo"
"; 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" | ";Echo"
";Echo"
";
?>