A class connecting odbc to mssql paging
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 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;
}
$ 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 ();
?>
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.