php pdo paging supports mysql and access

Source: Internet
Author: User
Keywords Network programming PHP tutorial
Tags access asp class code cost echo function get

This cost me a lot of time, the use of php, my head is mysql, it has been affected by a paging category, access is not supported limit page, like the same key, the problem solved immediately.
See comments should be easy to understand, access paging sql from asp json google code up
001 <? Php

002 / **

003 // paging class

004 * /

005 class Page {

006

007 // field property

008 public $ param; // paging parameters

009

010 public $ pagesize; // per page size

011

012 public $ sql; / / When the database access, invalid

013

014 public $ conn;

015

016 // Set the database type

017 public $ dbtype;

018

019 // When the database access configuration items

020 public $ tbname; / / table name

021

022 public $ prikey; / / primary key

023

024 // public $ url;

025

026 public function __set ($ name, $ value) {

027 $ this -> $ name = $ value;

028}

029 // initialization

030 public function __construct () {

031

032 // $ this-> conn = new mysqli ("localhost", "root", "147258", "empirecms");

033 // $ this-> conn-> set_charset ('utf8');

034

035}

036

037 // destroyed

038 public function __destruct () {

039}

040

041 // start

042 public function getStart () {

043

044 // $ param = $ this-> param;

045

046 $ param = (isset ($ _ GET [$ this-> param]))? $ _GET [$ this-> param]: 1;

047

048 return ($ param-1) * $ this-> pagesize;

049}

050 // generate SQL statements

051 // mysql

052 public function getMysqlSql () {

053 return $ this-> sql. "Limit". $ This-> getStart (). ",". $ This-> pagesize. "";

054 // return "test";

055}

056 / / Access query, reference json asp google

057 public function getAccessSql () {

058 $ end_n = $ this-> getStart () + $ this-> pagesize;

059

060 if ($ end_n> $ this-> pagesize) {

061 $ accsql = "SELECT TOP". $ This-> pagesize. "* FROM [". $ This-> tbname. "] As a where Not Exists (Select * From (Select Top". $ This-> getStart () . "* From [". $ This-> tbname. "] Order by [". $ This-> prikey. "] DESC) b Where b. [". $ This-> prikey. "] = A. [" $ this-> prikey. "]) ORDER BY a. [". $ this-> prikey. "] DESC";

062} else {

063 $ accsql = "SELECT TOP". $ This-> pagesize. "* FROM [". $ This-> tbname. "] ORDER BY [". $ This-> prikey. "] DESC";

064}

065

066 return $ accsql;

067

068}

069

070 // Get the record

071 public function getRecordSet () {

072 switch ($ this-> dbtype) {

073 case "ACCESS":

074 $ ssql = $ this-> getAccessSql ();

075 break;

076 case "MYSQL":

077 $ ssql = $ this-> getMysqlSql ();

078 break;

079}

080

081 $ rs1 = $ this-> conn-> query ($ ssql);

082

083 return $ rs1;

084}

085 // Get the total number of pages

086 public function getPageCount () {

087

088 return $ this-> getRecordCount () / $ this-> pagesize;

089

090}

091 // Get the total number of records

092 public function getRecordCount () {

093 $ rs = $ this-> conn-> query ("select count (*) from [". $ This-> tbname. "]");

094 $ row = $ rs-> fetchColumn ();

095 return $ row;

096}

097

098 // Get page navigation

099 public function getPageTool () {

100

101 $ pagecount = round ($ this-> getPageCount ());

102

103 $ param = (isset ($ _ GET [$ this-> param]))? $ _GET [$ this-> param]: 1;

104

105 if ($ param <= 1) {

106 echo "Home Previous";

107} else {

108 echo "<a href='?"$$$is-> param." = 1 '> Home </a> <a href='?"$$$is-> param. "=". ($ Param-1 ). ""> Previous </A> ";

109}

110 if ($ param> = $ pagecount) {

111 echo "next page last page";

112} else {

113 echo "<A href='?"$this-> param." = ". ($ Param +1)." '> Next Page </A> <A href='?".$this-> param. "=". $ pagecount. "'> LastPage </A>";

114}

115}

116}

117?>

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.