codeigniter 模型没有 return 限制定义的结果

codeigniter model does not return results as defined on limt

这是我的模型

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');


        }

在我的控制器中,我将其分配为

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

在我看来,我已经像

那样实现了它
<div class="col-md-8 col-lg-8">
            <!-- artigo em destaque -->
            <?php if ($news->num_rows()):?>
            <?php foreach ($news->result() as $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>

这个查询 给我结果但是如果我把限制 3 它给 2 如果我放 2 它给 1 如果我放 1 它不会给出任何结果为什么?

如果你回显 $news->num_rows() 会发生什么?我怀疑这可能与以下内容有关:

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

您得到的行数是否与您的限制相同,但它正在过滤掉最近的行,因为它不是 cat_id == 17?