/*************************************** ****** Class Name: PageSupport Function: displays MySQL Data by page. **************************************** *******/ Class PageSupport { // Attributes Var $ SQL; // SQL query statement of the data to be displayed Var $ page_size; // maximum number of lines per page Var $ start_index; // the sequence number of the first row of the record to be displayed Var $ total_records; // The total number of records. Var $ current_records; // number of records read on the current page Var $ result; // read the result Var $ total_pages; // total number of pages Var $ current_page; // current page number Var $ display_count = 30; // The first and last pages displayed Var $ arr_page_query; // array, which contains the parameters to be passed for pagination Var $ first; Var $ prev; Var $ next; Var $ last; // Method /*************************************** ****** Construct () Input parameters: $ Ppage_size: Maximum number of lines per page **************************************** *******/ Function PageSupport ($ ppage_size) { $ This-> page_size = $ ppage_size; $ This-> start_index = 0; } /*************************************** ****** Constructor :__ destruct () Input parameters: **************************************** *******/ Function _ destruct () {
} /*************************************** ****** Get function :__ get () **************************************** *******/ Function _ get ($ property_name) { If (isset ($ this-> $ property_name )) { Return ($ this-> $ property_name ); } Else { Return (NULL ); } } /*************************************** ****** Set function :__ set () **************************************** *******/ Function _ set ($ property_name, $ value) { $ This-> $ property_name = $ value; } /*************************************** ****** Function Name: read_data Function: reads records from a table based on SQL query statements. Returned value: Two-Dimensional attribute array result [Record Number] [field name] **************************************** *******/ Function read_data () { $ Ql = $ this-> SQL; // Query data, database links, and other information should be implemented outside class calls $ Result = _ query ($ psql) or die (mysql_error ()); $ This-> total_records = mysql_num_rows ($ result ); // Use the LIMIT keyword to obtain the record to be displayed on this page If ($ this-> total_records> 0) { $ This-> start_index = ($ this-> current_page-1) * $ this-> page_size; $ Psql = $ psql. "LIMIT". $ this-> start_index. ",". $ this-> page_size; $ Result = mysql_query ($ psql) or die (mysql_error ()); $ This-> current_records = mysql_num_rows ($ result ); // Put the query result in the result Array $ I = 0; While ($ row = mysql_fetch_Array ($ result )) { $ This-> result [$ I] = $ row; $ I ++; } } // Obtain the total number of pages and current page information $ This-> total_pages = ceil ($ this-> total_records/$ this-> page_size );
$ This-> first = 1; $ This-> prev = $ this-> current_page-1; $ This-> next = $ this-> current_page + 1; $ This-> last = $ this-> total_pages; } /*************************************** ****** Function Name: standard_navigate () Function: displays the home page, next page, last page, and not pages. **************************************** *******/ Function standard_navigate () { Echo" "; Echo ""; Echo" ";} /*************************************** ****** Function Name: full_navigate () Function: displays the home page, next page, last page, and not pages. Generate navigation links such as 1 2 3... 10 11 **************************************** *******/ Function full_navigate () { Echo" "; Echo ""; Echo" ";} } ?> Call: Include_once ("../config_jj/sys_conf.inc "); Include_once ("../PageSupportClass. php"); // paging class Include_once ('../smarty_jsnhclass.php '); $ Smarty = new Smarty_Jsnh (); Include_once ("../include/Smarty_changed_dir.php "); $ Smarty-> assign ('title', "Smarty news paging test "); $ PageSupport = new PageSupport ($ PAGE_SIZE); // instantiate the PageSupport object $ Current_page = $ _ GET ["current_page"]; // the current page number. If (isset ($ current_page )){ $ PageSupport->__ set ("current_page", $ current_page ); } Else { $ PageSupport->__ set ("current_page", 1 ); } ?> $ PageSupport->__ set ("SQL", "* from news "); $ PageSupport-> read_data (); // read data If ($ pageSupport-> current_records> 0) // if the data is not empty, assemble the data { For ($ I = 0; $ I <$ pageSupport-> current_records; $ I ++) { $ Title = $ pageSupport-> result [$ I] ["title"]; $ Id = $ pageSupport-> result [$ I] ["id"]; $ News_arr [$ I] = array ('News' => array ('id' => $ id, 'title' => $ title )); } } // Close the database Mysql_close ($ db ); $ Pageinfo_arr = array ( 'Total _ records '=> $ pageSupport-> total_records, 'Current _ page' => $ pageSupport-> current_page, 'Total _ pages' => $ pageSupport-> total_pages, 'First' => $ pageSupport-> first, 'Prev' => $ pageSupport-> prev, 'Next' => $ pageSupport-> next, 'Last' => $ pageSupport-> last ); $ Smarty-> assign ('results', $ news_arr ); $ Smarty-> assign ('pagesupport ', $ pageinfo_arr ); $ Smarty-> display ('news/list. tpl '); ?> Template list. tpl {* I am a Smarty comment, I don't exist in the compiled output *} {* {$ PageSupport. total_records}
{$ PageSupport. current_page}
{$ PageSupport. total_pages}
{$ PageSupport. first}
{$ PageSupport. prev}
{$ PageSupport. next}
{$ PageSupport. last}
*}
{$ Title}
{Foreach item = o from = $ results} {$ O. news. id} {$ o. news. title}
{Foreachelse} No data you want to view! {/Foreach}
{If ($ pageSupport. total_records> 0 )}
{/If}
|