2017-12-25 7 views
0

"추가로드"버튼에 문제가 있습니다. 결과가 더 이상 없다면 결과가 (1) 제한 인 20 (2)보다 작 으면 버튼을 숨기고 싶습니다. 모든 것이 이미 표시됩니다. 현재, 최선의 노력에도 불구하고 여전히 볼 수 있습니다.결과가 <= 한계에 도달하면 더 많은 버튼을 숨김 CI

내 한계는 20이며 만 4 결과가 있기 때문에 더 버튼이 숨겨져 야이 부하 :

컨트롤러 코드 :

public function get_topic($user_id='') 
    { 
     $this->load->helper('text'); 
     $page = $_GET['page']; 
     $value['posts'] = $this->user_model->get_userpost($user_id,$page); 
     $this->load->view('themes/default/user/user_topic_post',$value); 
    } 

모델 코드 :

// get topic post 
    function get_userpost($user_id,$page) 
    { 
     $offset = 20 * $page; 
     $limit=20; 
     $this->db->where('status',1); 
     $this->db->where('user_id',$user_id); 
     $this->db->limit($limit); 
     $this->db->offset($offset); 
     $this->db->order_by('id','DESC'); 
     $query = $this->db->get('threads'); 
     return $query; 
    } 

user_topic_post 코드 :

<?php 
$CI = get_instance(); 
$i = 0; 
foreach($posts->result() as $post): 
$i++; 
?> 
<tr> 
    <th scope="row">#<?php echo $i ?></th> 
    <td><a href="<?php echo base_url("topic/".$post->thread_slug);?>"><?php echo $post->title; ?></a><br/> 
    <small class="num-result"><?php echo strip_tags(word_limiter($post->content,20)); ?><br/><b> 
    <?php 
    $posted_date = $post->created_at; 
    $now = time(); 
    echo timespan($posted_date, $now, 1).'&nbsp'.lang_key('ago'); ?></b></small></td> 
    <td class="num-result text-center"><?php echo custom_number_format($post->post_view); ?></td> 
    <td class="num-result text-center"><?php echo custom_number_format($CI->threads_model->countTopicReplyByTopicId($post->id)); ?></td> 
</tr> 
<?php 
endforeach; //foreach 
?> 

내 JS 코드 :

<script> 
     $(document).ready(function(){ 
      userpost(0); 

      $(".load-more").click(function(e){ 
       e.preventDefault(); 
       var page = $(this).data('val'); 
       userpost(page); 

      }); 

     }); 

     var userpost = function(page){ 
      $(".user-topic-post-loading").show(); 
      $(".load-more").show(); 
      $.ajax({ 
       url: "<?php echo base_url("user/get_topic/".$account['id']); ?>", 
       type:'GET', 
       data: {page:page} 
      }).done(function(response){ 
       $(".user-topic-post").append(response); 
       $(".user-topic-post-loading").hide(); 
       $('.load-more').data('val', ($('.load-more').data('val')+1)); 
       if(response == ""){ 
        $(".load-more").hide(); 
       } 
      }); 

     };  
     </script> 
+0

설명이 약간 분명하지 않습니다. 이해하기 쉽도록 수정할 수 있습니까? 아마도 총알 점을 사용하십시오. – Alex

+0

비디오를 추가하겠습니까? –

답변

1

그럼 당신은 당신의 일 함수에 두 개의 변수를 보낼 필요 하나에 표시 할 결과가없는 경우 인 결과가 20보다 작 으면 조건을, 다른 하나는 추가 할 뷰 데이터입니다.

PHP :

public function get_topic($user_id = '') { 
    $this->load->helper('text'); 
    $page = $_GET['page']; 
    $items_per_page = 20; 
    $posts = $this->user_model->get_userpost($user_id, $items_per_page, $page); 
    if ($posts->num_rows() < $items_per_page) { 
     $msg = 'done'; 
    } else { 
     $msg = 'success'; 
    } 
    if ($posts->num_rows() > 0) { 
     $body = $this->load->view('themes/default/user/user_topic_post', array('posts' => $posts), true); 
    } else { 
     $body = ''; 
    } 
    $this->output->set_content_type('application/json'); 
    $this->output->set_output(json_encode(array('msg' => $msg, 'body' => $body))); 
    $this->output->_display(); 
    exit; 
} 

public function get_userpost($user_id, $per_page, $page) { 
    $this->db->where('status', 1); 
    $this->db->where('user_id', $user_id); 
    $this->db->limit($per_page); 
    $this->db->offset($per_page * $page); 
    $this->db->order_by('id', 'DESC'); 
    return $this->db->get('threads'); 
} 

JS : 또한 $page 가져 오기 var에 정수는 것을 확인하는 것이 좋습니다

var userpost = function (page) { 
    $(".user-topic-post-loading").show(); 
    $(".load-more").show(); 
    $.ajax({ 
     url: "<?php echo base_url("user/get_topic/" . $account['id']); ?>", 
     type: 'GET', 
     data: { 
      page: page 
     }, 
     dataType: 'json' 
    }).done(function (response) { 
     $(".user-topic-post").append(response.body); 
     $(".user-topic-post-loading").hide(); 
     if (response.msg == "done") { 
      $(".load-more").hide(); 
     } else { 
      $('.load-more').data('val', ($('.load-more').data('val') + 1)); 
     } 
    }); 

}; 

당신이 뭔가를 시도 할 수 있습니다. 그렇지 않으면 일부 사용자가 문자열을 넣을 수 있으며 쿼리 작성기에서 기본적으로 이스케이프 처리되지만 확실하게 오류가 반환됩니다.

+0

나는 그것을 시험해 보겠습니다. –

+0

오류가 없지만 결과가 없습니다. –

+0

지금 작동하지만로드가 더 많은 버튼을로드해도로드 된 데이터가 남아 있어도 표시되지 않습니다. –

관련 문제