Examples of db classes in zf framework by page

Source: Internet
Author: User
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" ";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.