zf架構db類的分頁樣本分享_php執行個體

來源:互聯網
上載者:User
zf架構的分頁樣本
複製代碼 代碼如下:
isset($_GET['page']) ? $page = $_GET['page'] : $page = 1;
//引入Loader類(自動載入類)
require_once("Zend/Loader.php");
//使用Loader類引入一個Db類
Zend_Loader::loadClass("Zend_Db");
//引入Zend_Db的狀態器
Zend_Loader::loadClass("Zend_Db_Statement_Pdo");
//設定資料庫串連資訊
$Config = array('host' => '127.0.0.1' ,
'username' => 'root' ,
'password' => '111' ,
'dbname' => 'test',
'profiler' => "true"
);
//告訴Zend_Db類所操作的資料庫和資料庫配置資訊
$Db = Zend_Db::factory('PDO_Mysql' , $Config);
//執行編碼語句
$Db -> query("set names utf8");
//-----------------------------------------------
//使用fetchOne()方法得出表的總條數
$Total = $Db -> fetchOne("select count(*) from gongsi");
//定義每頁顯示條數
$B = 50;
//得出總頁數
$A = ceil($Total/$B);

//-----接下來為一系列的查詢表、取結果集、分頁等操作
$Select = $Db ->select();
$Select -> from('sanguo',array('s_sheng as 省份','sum(s_gongzi) as 總工資','min(s_gongzi) as 最低工資','max(s_gongzi) as 最高工資','avg(s_gongzi) as 平均工資'));
// $Select -> Where('s_gongzi>=3000');
// $Select -> Where("s_sheng='河北'");
// $Select -> order('s_sheng asc');
// $Select -> order('s_gongzi desc');
$Select -> group('s_sheng'); //分組
//$Select -> having('最高工資>10000'); //附加條件
$Select -> order('最高工資 desc'); //排序
$Select -> limit(0,0); //截取
$Select -> limitPage($page, $B); //分頁
/*SQL語句相當於:
select s_sheng as 省份,sum(s_gongzi) as 最高工資 from sanguo group by s_sheng having 最高工資>10000 order by 最高工資 desc limit 0,10;
*/
$Result = $Db->fetchAll($Select);

echo "















";echo " ";foreach ($Result as $key => $value) { echo " "; foreach ($value as $key2 => $value2) { echo " "; } echo " ";}echo " ";echo " ";echo " ";echo "
省份 總工資 最低工資 最高工資 平均工資
" . $value2 . "
";
echo "首頁 ";
if ($page>1)
{
echo "上頁 ";
}
for ($i=1; $i <=15 ; $i++)
{
echo "".$i." ";
}
if ($page<$Total)
{
echo "下頁 ";
}
echo "末頁";
echo "
";
?>
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.