Page example of the ZF framework
Copy CodeThe code is as follows:
Isset ($_get[' page ')? $page = $_get[' page ']: $page = 1;
Introducing the loader class (auto-load Class)
Require_once ("zend/loader.php");
Introducing a DB class using the Loader class
Zend_loader::loadclass ("zend_db");
Introducing the ZEND_DB State device
Zend_loader::loadclass ("Zend_db_statement_pdo");
Configure Database connection Information
$Config = Array (' host ' = ' 127.0.0.1 ',
' Username ' = ' root ',
' Password ' = ' 111 ',
' dbname ' = ' test ',
' Profiler ' = ' true '
);
Tells the zend_db class what database and database configuration information to manipulate
$Db = zend_db::factory (' Pdo_mysql ', $Config);
Executing an encoded statement
$Db, Query ("Set names UTF8");
//-----------------------------------------------
Use the Fetchone () method to derive the total number of bars in a table
$Total = $Db Fetchone ("SELECT count (*) from Gongsi");
Define the number of bars to display per page
$B = 50;
The total number of pages reached
$A = Ceil ($Total/$B);
-----followed by a series of query tables, result sets, paging and other operations
$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 maximum wage ') , ' avg (S_gongzi) as average wage '));
$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 (' Maximum wage >10000 '); Additional conditions
$Select order (' highest wage desc '); Sort
$Select, limit (0,0); Intercept
$Select-Limitpage ($page, $B); Page out
The/*sql statement is equivalent to:
Select S_sheng as Province, sum (S_gongzi) as maximum wage from Sanguo Group by S_sheng have the highest wage >10000 order by highest wage desc limit 0,10 ;
*/
$Result = $Db->fetchall ($Select);
echo "
"; Echo"
Provinces |
Total Wages |
Minimum wage |
Maximum wage |
Average wage |
"; foreach ($Result as $key = + $value) {echo"
"; foreach ($value as $key 2 = + $value 2) {echo "
" . $value 2. " | "; } echo "
";} echo "
"; Echo"
"; echo "Home"; if ($page >1) { echo "on page"; } for ($i =1; $i <=15; $i + +) { echo "". $i. " "; } if ($page < $Total) { echo "Next page"; } echo "Last"; echo " | "; Echo"
"; Echo"
";
?>