Simple code for loading more results

Source: Internet
Author: User
JS <SCRIPT type = "text/JavaScript"> // defines the global variable, used to calculate the page var more_ I = 1; $ ('# showmore '). click (function () {$. ajax ({type: 'get', URL: '_ URL _/ajax_more', data: {'evalue _ id': {$ evalue_info.evalue_id}, 'num ': more_ I,}, datatype: 'json', success: function (RES) {If (RES = 0) {alert ('No More data ');} else {$ ('# prev_more '). before (RES ['info']); more_ I = res ['num'] + 1 ;},}) ;}); </SCRIPT>
PHP, using the TP framework/* ajax to load more */Public Function ajax_more (){
// Instantiate the model $ doctor_evalue_reply = m ('Doctor _ evalue_reply ');
// Obtain the data passed by Ajax. $ evalue_id = $ this-> _ Get ('evalue _ id', 'intval '); $ num = $ this-> _ Get ('num', 'intval ');
// Calculate the page $ start = $ num * 5; // obtain the data $ condition ['evalue _ id'] = $ evalue_id; $ reply_info = $ doctor_evalue_reply-> Field ('reply _ id, user_name, content, add_time ')-> where ($ condition)-> limit ($ start. ', 5')-> Order ('add _ time DESC')-> select (); if ($ reply_info = NULL) {$ res = 0;} else {
// The server sends the num number ++ back to the JS client for calling. $ Res ['num'] = $ num ++; // assemble the data into HTML and foreach ($ reply_info as $ key => $ value) {$ temp = $ start + $ key + 1; $ HTML. = '<tr class = "'. $ vlaue ['reply _ id']. '">'; $ HTML. = '<TD> <input name = "id []" value = "'. $ value ['reply _ id']. '"type =" checkbox "/> </TD>'; $ HTML. = '<TD> '. $ temp. '</TD>'; $ HTML. = '<TD> '. $ value ['user _ name']. '</TD>'; $ HTML. = '<TD Title = "'. $ value ['content']. '"> '. mb_substr ($ value ['content'], 0, 35, 'ut F-8 '). '... </TD> '; $ HTML. = '<TD> '. date ('Y-m-d h: I: s', $ value ['add _ time']). '</TD>'; $ HTML. = '<TD> <input type = "button" value = "delete" class = "button" onclick = "If (confirm (\' Are you sure you want to delete this doctor? \ ') Del ('. $ value ['reply _ id']. '); "/> </TD>'; $ HTML. = '</tr>';} $ res ['info'] = $ HTML ;}
// Return echo json_encode ($ res) in JSON format );}

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.