An example of PHP + MSSQL Paging
Last Update:2018-12-08
Source: Internet
Author: User
<?
Require "config. php ";
DL ("extensions/php_mssql70.dll ");
If (! Isset ($ page) {$ page = 1 ;}
If ($ page <= 0) {$ page = 1 ;}
$ Db = mssql_connect ($ local, $ user, $ pass );
Mssql_select_db ($ name, $ dB );
$ Query = mssql_query ("select count (*) as date from news", $ dB );
$ Query = mssql_fetch_array ($ query );
$ Pages = Ceil ($ Query [0]/$ userperpage );
If ($ page >$ pages) {$ page = $ pages ;}
If ($ Query [0] <$ userperpage) {$ userperpage = $ Query [0];}
$ Dangqian = ($ page-1) * $ userperpage;
Echo "<title> News </title> ";
Echo "<style type = text/CSS> \ n ";
Echo "<! -- \ N ";
Echo "A {text-Decoration: None} \ n ";
Echo "A: hover {color: Blue; text-Decoration: underline} \ n ";
Echo "TD {font-size: 9pt} \ n ";
Echo "--> </style> \ n ";
Echo "<Div align = center> <center> \ n ";
Echo "<Table border = 0 width = 100% cellspacing = 0 cellpadding = 0 Height = 19 \ n ";
Echo "<tr> ";
Echo "<TD width = 52% colspan = 5> </TD> </tr> \ n ";
Echo "<tr> ";
Echo "<TD width = 52% Height = 19 valign = bottom bgcolor = # b5c6b0> <p align = center> <font \ n ";
Echo "color = #408080> News Title </font> </TD> \ n ";
Echo "<TD width = 14% Height = 19 valign = bottom align = center bgcolor = # b5c6b0> <font \ n ";
Echo "color = #408080> publication date </font> </TD> \ n ";
Echo "<TD width = 19% Height = 19 valign = bottom align = center bgcolor = # b5c6b0> <font \ n ";
Echo "color = #408080> posting Department </font> </TD> \ n ";
Echo "<TD width = 7% Height = 19 valign = bottom align = center bgcolor = # b5c6b0> <font \ n ";
Echo "color = #408080> Read </font> </TD> \ n ";
Echo "<TD width = 8% Height = 19 valign = bottom align = center bgcolor = # b5c6b0> <font \ n ";
Echo "color = #408080> image </font> </TD> \ n ";
Echo "</tr> \ n ";
Echo "</table> \ n ";
Echo "</center> </div> \ n ";
Echo "<Div align = center> <center> \ n ";
Echo "<Table border = 0 width = 100% cellspacing = 0 cellpadding = 0 Height = 19> \ n ";
$ Db = mssql_connect ($ local, $ user, $ pass );
Mssql_select_db ($ name, $ dB );
$ Query = mssql_query ("select * from news order by date DESC", $ dB );
$ RORO = mssql_num_rows ($ query );
If ($ RORO = 0 ){
Echo "<br> <p align = \" center \ "> <font color = \" # ff0000 \ "size = \" 2 \ "> <marquee behavior = \ "alternate \" border = \ "0 \" width = \ "300 \" Height = \ "16 \" scrolldelay = \ "70 \"> no record exists in the database currently! </Marquee> </font> </P> ";
Exit;
}
Mssql_data_seek ($ query, $ dangqian );
$ I = 0;
While ($ arr = mssql_fetch_array ($ query )){
If ($ I >=$ userperpage) {break ;}
Echo "<tr> \ n ";
Echo "<TD width = 52% bgcolor = # f3f3f3 Height = 19 valign = bottom> <p align = left> <a href = \" readnews. php? Id = $ arr [date] \ "target = \" _ blank \ "> <font color = #3d5449> $ arr [title] </font> </a> </ TD> \ n ";
$ Datee = date ("Y-m-d", $ arr [date]);
Echo "<TD width = 14% bgcolor = # f3f3f3 Height = 19 valign = bottom align = center> <font color = #3d5449> $ datee </font> </TD> \ n ";
Echo "<TD width = 19% bgcolor = # f3f3f3 Height = 19 valign = bottom align = center> <font color = #3d5449> $ arr [type] </font> </TD> \ n ";
Echo "<TD width = 7% bgcolor = # f3f3f3 Height = 19 valign = bottom align = center> <font color = #808080> $ arr [click] </font> </TD> \ n ";
Echo "<TD width = 8% bgcolor = # f3f3f3 Height = 19 valign = bottom align = center> \ n ";
$ Arr [Photo] = trim ($ arr [Photo]);
If ($ arr [Photo] <> "") | (file_exists ($ arr [Photo]) {
Echo " ";
}
Else {echo "";}
Echo "</TD> \ n ";
Echo "</tr> \ n ";
$ I ++;
} // While
Echo "<tr> \ n ";
Echo "<TD width = 100% Height = 20 colspan = 5> </TD> \ n ";
Echo "</tr> \ n ";
Echo "<tr> <TD width = 100% colspan = 5> <center> \ n ";
If ($ page <> 1 ){
Echo "<a href = $ php_self? Page = 1> <font color = #408080> homepage </font> </a> \ n ";
}
If ($ page> 1 ){
$ Upage = $ page-1;
Echo "<a href = $ php_self? Page = $ upage> <font color = Red> previous page </font> </a> \ n ";
}
For ($ y = 1; $ Y <= $ pages; $ y ++ ){
Echo "<a href = $ php_self? Page = $ Y> $ Y </a> \ n ";
}
If ($ page <$ pages ){
$ Npage = $ page + 1;
Echo "<a href = $ php_self? Page = $ npage> <font color = Red> next page </font> </a> \ n ";
}
If ($ page <> $ pages ){
Echo "<a href = $ php_self? Page = $ pages> <font color = #408080> last page </font> </a> \ n ";
}
Echo "</center> </TD> \ n ";
Echo "</tr> \ n ";
Echo "</table> \ n ";
Echo "</center> </div> \ n ";
?>