An odbc-connected mssql paging class _ PHP Tutorial

Source: Internet
Author: User
A class connecting odbc to mssql paging .! -- Erquan. net --? ClassPages {var $ cn; connection database cursor var $ d; connection data table cursor var $ result; result var $ dsn; dsn source var $ user; user name var $ pass; password var
Class Pages {
Var $ cn; // database connection cursor
Var $ d; // The cursor connecting to the data table
Var $ result; // result
Var $ dsn; // dsn source
Var $ user; // user name
Var $ pass; // password

Var $ total; // The total number of records.
Var $ pages; // The total number of pages.
Var $ onepage; // number of entries per page
Var $ page; // current page
Var $ fre; // Previous Page
Var $ net; // Next page
Var $ I; // control the display of each page

Function getConnect ($ dsn, $ user, $ pass ){
$ This-> cn = @ odbc_connect ($ dsn, $ user, $ pass );
If (! $ This-> cn ){
$ Error = "database connection error ";
$ This-> getMess ($ error );
}
}

Function getDo ($ SQL) {// query data from the table
$ This-> d = @ odbc_do ($ this-> cn, $ SQL );
If (! $ This-> d ){
$ Error = "a small error occurred while querying ......";
$ This-> getMess ($ error );
}
Return $ this-> d;
}

Function getTotal ($ SQL ){
$ This-> SQL = $ SQL;
$ DT = $ this-> getDo ($ this-> SQL); // calculates the cursor of the total number.
$ This-> total = odbc_result ($ dT, 'total'); // why can't we $ this-> d here?
Return $ this-> total;
}

Function getList ($ SQL, $ onepage, $ page ){
$ This-> s = $ SQL;
$ This-> onepage = $ onepage;
$ This-> page = $ page;
$ This-> dList = $ this-> getDo ($ this-> s); // connects the table cursor
$ This-> pages = ceil ($ this-> total/$ this-> onepage );
If ($ this-> pages = 0)
$ This-> pages ++; // you cannot obtain page 0th.
If (! Isset ($ this-> page ))
$ This-> page = 1;
$ This-> fre = $ this-> page-1; // Number of pages to be displayed
$ This-> nxt = $ this-> page + 1;
$ This-> nums = ($ this-> page-1) * $ this-> onepage;
// If ($ this-> nums! = 0 ){
// For ($ this-> I = 0; $ this-> I <$ pg-> getNums (); odbc_fetch_row ($ this-> dd ), $ this-> I ++); // same as above
//}
// $ This-> I = 0; // why cannot this part be encapsulated?
Return $ this-> dList;
}

Function getFanye (){
$ Str = "";
If ($ this-> page! = 1)
$ Str. = "homepage fre."> Previous Page ";
Else
$ Str. = "front page of the home page ";
If ($ this-> page <$ this-> pages)
$ Str. = "nxt."> BACK page ";
Else
$ Str. = "back page ";
If ($ this-> page! = $ This-> pages)
$ Str. = "pages."> last page ";
Else
$ Str. = "Last page ";

$ Str. = "total". $ this-> pages. "page ";
$ Str. = "you are browsing the page". $ this-> page. "page ";
Return $ str;
}

Function getNums (){
Return $ this-> nums;
}

Function getOnepage () {// actual number of entries per page
Return $ this-> onepage;
}

Function getI (){
Return $ this-> I;
}

Function getPage (){
Return $ this-> page;
}

Function getMess ($ error) {// custom message
Echo" $ Error ";
Exit;
}
}

$ Pg = new Pages ();
$ Pg-> getConnect ("lei", "sa", "star ");
$ Pg-> getTotal ("select count (*) as total from xs"); // calculates the total number of connected student tables
$ Pg-> getList ("select xs_name from xs order by xs_id", 8, $ page );
If ($ pg-> getNums ()! = 0 ){
For ($ I = 0; $ I <$ pg-> getNums (); odbc_fetch_row ($ pg-> dList), $ I ++); // same as above
}
$ I = 0;
While (odbc_fetch_row ($ pg-> dList )){
$ Name = odbc_result ($ pg-> dList, "xs_name ");
Echo $ name ."
";
If ($ I = $ pg-> getOnepage () {// jump out of the loop
Break;
}
$ I ++;
}
Echo $ pg-> getFanye ();
?>

Http://www.bkjia.com/PHPjc/314636.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/314636.htmlTechArticle! -- Erquan. net --? Class Pages {var $ cn; // connection database cursor var $ d; // connection data table cursor var $ result; // result var $ dsn; // dsn source var $ user; // user name var $ pass; // password var...

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.