here i want to display images according to the numbers given
here is my view page

<div class="limiter hidden-xs">
                                        <label>Show</label>
                                        <select>
                                            <option selected="selected" value="">9</option>

                                            <option value="">12</option>
                                            <option value="">24</option>
                                            <option value="">36</option>
                                        </select>
                                        per page        
                                    </div>

my controler section is this

public function look_book() 
    {
        $data['active_mn']='look_book';
        $config['base_url'] = base_url().'roxcontrol/look_book';
        $config['per_page'] = 9;
        $config['uri_segment'] = 3;
        $config['total_rows'] = $this->roxmodel->count_gallery();
        $data['galery']=$this->roxmodel->get_gallery($config['per_page'],$this->uri->segment(3));

        $this->load->library('pagination',$config);
        $data['page_links'] = $this->pagination->create_links();
        $this->load->view('look_book',$data);
    }

my model page looks like this

public function get_gallery($num,$offset)
    {
      $this->db->order_by("gallery.id","desc");

      $query=$this->db->get('gallery',$num,$offset);
      return $query->result();
    }

i want to diplay according to the selected please help me

Dani AI

Generated

Two clear issues in the posted code explain why the selection has no effect: the <option> elements have empty value attributes, and the controller always uses a hard-coded per-page value. That combination makes the page silently ignore the chooser. needs the selected number to be sent to the controller and then used as the pagination per_page value; was right to ask for clarification because no runtime error will appear when the value is never sent.

A compact, reliable approach is to submit the chosen limit as a GET parameter and let the pagination use query-string offsets. The view can be a simple GET form (submit on change) and preserve the chosen option by passing the limit back to the view. Example (view):

<form method="get" id="perpageForm">
  <label>Show</label>
  <select name="limit" onchange="this.form.submit();">
    <option value="9"<?php if (isset($limit) && $limit==9) echo ' selected'; ?>>9</option>
    <option value="12"<?php if (isset($limit) && $limit==12) echo ' selected'; ?>>12</option>
    <option value="24"<?php if (isset($limit) && $limit==24) echo ' selected'; ?>>24</option>
    <option value="36"<?php if (isset($limit) && $limit==36) echo ' selected'; ?>>36</option>
  </select>
  per page
</form>

In the controller, read and validate the limit GET value, configure pagination to use query strings, and append the limit to pagination links so it persists across pages. Example (controller logic):

$limit = (int) $this->input->get('limit');
$allowed = [9,12,24,36];
if (!in_array($limit, $allowed)) $limit = 9;

$offset = (int) $this->input->get('offset');

$config['base_url'] = site_url('roxcontrol/look_book');
$config['per_page'] = $limit;
$config['page_query_string'] = TRUE;
$config['query_string_segment'] = 'offset';
$config['total_rows'] = $this->roxmodel->count_gallery();
$config['suffix'] = '?limit=' . $limit;
$config['first_url'] = $config['base_url'] . $config['suffix'];

$this->load->library('pagination', $config);
$data['gallery'] = $this->roxmodel->get_gallery($limit, $offset);
$data['page_links'] = $this->pagination->create_links();
$data['limit'] = $limit;
$this->load->view('look_book', $data);

Notes and cautions: cast and whitelist the limit to prevent odd values; ensure offsets are non-negative and consistent with the limit; if the CodeIgniter version supports reuse_query_string, that can simplify keeping query params, otherwise use suffix/first_url as shown. An alternative is storing the chosen limit in session so URL changes are not required, but the GET approach is simplest and bookmark-friendly.

Member Avatar for Member #120589

ANy chance of you explaining what's not working? Dumping your code and asking a vague question ain't much help. Getting any errors?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.