Next, let's start writing a procedure showing the message -------------------------------------- --------------------------------------- For brief, we build a simple table here Guestbook, field three gb_id, gb_name, GB_Content table is built, fill in a few records of easy test (with: I used the database is mysql)
Then write a database connection program GB_CONN.INC.PHP is placed in the incapacity code as follows: PHP
Mysql_connect ("LocalHost", "root", "") or Die ("Sorry, Can't Connect Data Server!"); mysql_select_db ("test") or Die ("Sorry, Can't Open Database!");
EXTRACT ($ _ get); extract ($ _ pos);
?>
Write a single page processing function, write into gb_function.php, file in function Php / * ========================= ============================================================================================================================================================================================================= == ** file name: gb_function.php * program features: custom function set * update time: 2004-09-02 ** programming: Jzealot * E-mail: web-xy@163.com**=== ============================================================================================================================================================================================================= =========================== * /
/ ************************************************** Function Name: Pagedeal () Functional function: paging processing ********************************************************************************************************************************* Pagedeal ($ pageSQL, $ pageize) {Global $ Recordcount, $ PageCount, $ page, $ startloc; $ = mysql_query ($ pageSQL); $ version = mysql_num_rows ($ r); // Total number of records // *** *** Calculate the total number of pages ****** / if ($ RecordCount% $ pageSize == 0) $ pageCOUNT = $ RecordCount / $ pageCOUNT = INTVAL ($ RecordCount / $ Pagesize) 1; IF (Empty ($ page) | $ up <1) // $ page is current page $ page = 1; if ($ page> $ pageCOUNT) $ page = $ pagecount; $ startloc = ($ PAGE - 1) * $ pageize; // Determine the start of the current page // ----------------- Digital page for the current page ------------ ---------- // IF ($ Page <= 5); $ i = 0;
IF ($ PAGE> 5 && $ PageCount - $ Page <5 && $ PageCount> 10) $ i = $ pageCOUNT - 10;
IF ($ PAGE> 5 && $ PageCount - $ Page> = 5) $ i = $ page - 5;
$ NUMPAGE [$ I] = $ I 1;
// ------------------------ / / $ J = $ PageCount;
IF ($ page <= 5 && $ pageCount> 10) $ j = 10;
IF ($ PAGE> 5 && $ PageCount - $ Page> = 5) $ J = $ PAGE 5;
For (;) $ numpage [$ i] = $ i 1;
Return $ Numpage; // Return to Numbers
}
?>
Finally, we will write a message display program GB_List.php Php / * ==================================== =================================================== ** file name: GB_LIST. php * program features: display message * updated: 2004-09-02 ** programming: Jzealot * E-mail: web-xy@163.com**============== ============================================================================================================================================================================================================= ================ * / include_once ("Inc / GB_Conn.inc.php"); / / Load Database Connection & Request Setting Include_once ("Inc / Smarty.inc.php" ); // Load SMARTY settings include_once ("function / gb_function.php");
/ / -------------------------------------------------------------------------------------------- -------------------------------- // Page process query data // ---------- -------------------------------------------------- -------------------- $ SQL = "SELECT GB_ID from Guestbook"; $ page = 5; $ fpage = "gb_list.php"; $ numpage = pagedeal ($ SQL, $ PAGESIZE); // Call the paging processing function
// ---------------------- Paging related template variable replacement -------------------- ----- / / $ smarty -> Assign ("Recordcount", $ RecordCount); // Total Documentary $ SMARTY -> Assign ("Page", $ Page); // Current Page $ SMARTY -> Assign "PageCount", $ PageCount); // Total Page $ Smarty -> Assign ("Prepage", $ Page-1); // Previous $ smarty -> Assign ("Nexpage", $ PAGE 1); // Next $ smarty -> Assign ("Numpage", $ Numpage); // Digital Page $ SMARTY -> Assign ("FPAGE", $ fpage); // To page the page // ----- -------------------------------------------------- ------------------------ // Query the data and pass to the template // ---------------- -------------------------------------------------- ------------- $ = mysql_query ("SELECT * FROM GUESTBOOK LIMIT $ STARTLOC, $ PageSize"); $ Num = 0; While ($ ROW = mysql_fetch_array ($ r)) {$ RSS [$ Num] = Array ("GB_NAME" => $ ROW ["GB_NAME"], "GB_Content" => $ ROW ["GB_Content"]); $ Num ; $ SMARTY -> Assign, $ RSS);
$ SMARTY -> Display ('GB_List.tpl'); // Display Template?>
Next, talk about the template
(Continued)