Cld Posted September 5, 2016 Share Posted September 5, 2016 Hello there, I have a button to load more news in web. And i need to hide that button after all the news from database is loaded. But i only got that button hidden after one press which is not all news or i cant hide it at all with my if functions. Heres my functions i use codeigniter. Controller: public function get_more_news($menu_item_id, $total){ $this->data['all_items']= $this->{$this->model}->get_items_all($menu_item_id, $this->lang_id); $this->data['total'] = $total + $this->items_per_page; $current_page = $this->input->get('page') ? (($this->input->get('page') - 1) * $this->items_per_page) - 1 : 0; $this->data['items'] = $this->{$this->model}->get_items($menu_item_id, $this->lang_id, $this->data['total'], $current_page); if ($all_items > $this->data['items']) { $this->data['hide_button'] = 1; } else { $this->data['hide_button'] = 0; } $this->data['use_thumbnails'] = $this->{$this->model}->get_variables('use_thumbnails'); $this->data['thumbnail_prefix'] = $this->{$this->model}->get_variables('thumbnail_prefix'); $this->data['directory'] = $this->{$this->model}->get_variables('directory'); $this->data['meta_data'] = $this->welcome_model->get_item_meta_data($menu_item_id, $this->lang_id, true); $this->load->view($this->theme . '/menu_modules/' . $this->module . '/loader', $this->data); } } Loader.php <div id="button_count" data-id="<?= $hide_button; ?> "style="display:none;"></div> <script> total= $('#masonry li').length; var button = $('#button_count').attr('data-id'); var button1 = Number(button); if(button1 === 0){ $('#LoadMoreNewsButton').hide(); } </script> This script hides the button instantly. Help me please Quote Link to comment Share on other sites More sharing options...
Cld Posted September 5, 2016 Author Share Posted September 5, 2016 Hehe i made it myself simply adding a line in controller and changing the if sentence. $this->data['items_now'] = count($this->data['items']); if ( $this->data['all_items'] > $this->data['items_now']) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.