Welcome Guest, Not a member yet? Register   Sign In
pagination problem
#1

[eluser]junaids[/eluser]
Hi,
I just tried the pagination class. And want to show one item per page. But it is not working and displaying 2 items per page. Here is my code
Code:
function show_products()
  {
    $this->load->library('pagination');
    $config['base_url'] = 'http://localhost/ci_series/gallery/show_products/';
    $config['total_rows'] = 4;
    $config['per_page'] = 1;
    $this->pagination->initialize($config);
    $this->load->model('Gallery_model');
    $data['products'] = $this->Gallery_model->show_products();
    $data['images'] = $this->Gallery_model->get_images();
    $this->load->view('show_products', $data);
  }
and view
Code:
<div id="blank_gallery">Product Description</div>
    &lt;?php foreach($products as $product): ?&gt;
    &lt;?php echo 'Product Name' ?&gt; :
    &lt;?php echo $product->name; ?&gt;<br>
    &lt;?php echo 'Product Price' ?&gt; :
    &lt;?php echo $product->price; ?&gt;<br>
    COLOR :&lt;?php echo $product->option_color; ?&gt;<br>
    SIZE :&lt;?php echo $product->option_size; ?&gt;<br>
    IMG: <img src="&lt;?php echo $images[ $product-&gt;id ]['url'] ?&gt;"/><br>
    THUMB: <img src="&lt;?php echo $images[ $product-&gt;id ]['thumb_url'] ?&gt;"/><br>
&lt;?php endforeach; ?&gt;
&lt;?php echo $this->pagination->create_links(); ?&gt;
Suggestions please..
#2

[eluser]InsiteFX[/eluser]
Because you are returning all records from the database, If you want to show just one record you need to return just one record! Then you are looping throught them all in your view.

Code:
$query->row();  // returns only one record




Theme © iAndrew 2016 - Forum software by © MyBB