Home >Backend Development >PHP Tutorial >Sharing of paging examples of zf framework db class_PHP tutorial
This article mainly introduces the paging example of the zf framework db class. The code is very simple. You can use it just by reading the comments
Pagination example of zf framework The code is as follows: '127.0.0.1' , 'username' => 'root' , 'password' => '111' , 'dbname' => 'test', 'profiler' => "true" ); //Tell the Zend_Db class the database and database configuration information operated by $Db = Zend_Db::factory('PDO_Mysql' , $Config); //Execute encoding statement $Db -> query("set names utf8"); //-------------------------------------------------- //Use the fetchOne() method to get the total number of entries in the table $Total = $Db -> fetchOne("select count(*) from gongsi"); //Define the number of items displayed on each page $B = 50; //Get the total number of pages $A = ceil($Total/$B); //-----The next step is a series of operations such as query tables, result sets, paging, etc. $Select = $Db ->select(); $Select -> from('sanguo',array('s_sheng as province','sum(s_gongzi) as total salary','min(s_gongzi) as minimum salary','max(s_gongzi) as maximum salary',' avg(s_gongzi) as average salary')); // $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>10000'); //Additional conditions $Select -> order('Highest salary desc'); //Sort $Select -> limit(0,0); //Interception $Select -> limitPage($page, $B); //Paging /*SQL statement is equivalent to: select s_sheng as province,sum(s_gongzi) as maximum salary from sanguo group by s_sheng having maximum salary>10000 order by maximum salary desc limit 0,10; */ $Result = $Db->fetchAll($Select); echo "Province | Total salary | Minimum salary | Maximum salary | < ;th>Average salary|
---|---|---|---|---|
" . $value2 . " | "; } 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 "