database - codeigniter model does not return results as defined on limt -


this model

function get_one_news($limit = 2, $offset = null) {              if ($limit) {                  $this->db->limit($limit, $offset);             }              $this->db->order_by('news.added_on', 'desc');              return $this->db->get('news');           } 

and in controller had assign

$data['news'] = $this->news_model->get_one_news(); 

in view had implement

<div class="col-md-8 col-lg-8">             <!-- artigo em destaque -->             <?php if ($news->num_rows()):?>             <?php foreach ($news->result() $n):?>             <?php if ($n->cat_id == 17):?>             <div class="featured-article">                 <a href="#">                 <?php if ($n->image != ''): ?>                     <img src="<?php echo base_url('uploads/'.$n->image);?>" alt="" class="thumb">                 <?php endif;?>                 </a>                 <div class="block-title">                     <h4><?php echo $n->title = word_limiter($n->title, 7);?></h4>                  </div>             </div>             <!-- /.featured-article -->             <?php endif;?>             <?php endforeach;?>             <?php endif;?>         </div> 

this query gives me result if put limit 3 gives 2 if put 2 gives 1 , if put 1 wont give result why ?

what happens if echo $news->num_rows()? suspect might have with:

<?php if ($n->cat_id == 17):?> 

are getting same number of rows limit filtering out recent 1 because isn't cat_id == 17?


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -