Provides various official and user-released code examples. For code reference, you are welcome to exchange and learn about this function. This function is required when you implement the "Previous Page" and "next page" navigation links, however, the document IDs are generally inconsistent, so you cannot use the id of the current page plus one minus one. Instead, you can query the IDs of the records in the upper and lower rows of the database. The function is now written as follows:
Function article_guide ($ current_id, $ table_name) {// $ current_id is generally obtained through get
$ A = M ($ table_name); // A = article
$ Result = $ A-> order ('Id ASC ')-> select ();
$ Guide ['min _ id'] = $ link [0] ['id']; // the smallest id in the database
$ Guide ['max _ id'] = $ link [count ($ result)-1] ['id']; // The largest id in the database
// Obtain the ID of the previous Article
$ Prev_id = $ current_id-1;
While ($ A-> where ('Id = "'. $ prev_id.'" ')-> getField ('id') = false ){
If ($ prev_id <= $ min_id ){
$ Prev_id = '-1'; // indicates the earliest article
Break;
}
$ Prev_id --;
}
// Obtain the id of the next article
$ Next_id = $ current_id + 1;
While ($ A-> where ('Id = "'. $ next_id.'" ')-> getField ('id') = false ){
If ($ next_id> = $ max_id ){
$ Next_id = '-2'; // indicates the latest article.
Break;
}
$ Next_id ++;
}
$ Guide ['Next _ id'] = $ next_id;
$ Guide ['prev _ id'] = $ prev_id;
Return $ guide;
}
Call this function in the operation you need, assign values to the template, and add the corresponding id to the next page of the previous page.
You can also use the id to determine whether the page can be accessed:
I ('get. id') =-1? $ This-> error ('no earlier articles! ', 'Index'): false;
I ('get. id') =-2? $ This-> error ('no updated article! ', 'Index'): false;
AD: truly free, domain name + VM + enterprise mailbox = 0 RMB