ZF Framework DB Class pagination sample sharing _php instances

Source: Internet
Author: User
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" "; foreach ($Result as $key = + $value) {echo" "; foreach ($value as $key 2 = + $value 2) {echo " "; } echo " ";} echo " "; Echo" "; Echo" "; Echo"
Provinces Total Wages Minimum wage Maximum wage Average wage
" . $value 2. "
";
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 "
";
?>
  • 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.