Welcome Guest, Not a member yet? Register   Sign In
Duplicate content with findAll() - CI4
#1

In my model this is present:

PHP Code:
public function lastComments($limit){
        return $this->from('comments')
            ->findAll($limit);
    


It then takes all the last tot * comments from the 'comments' table.
I created a loop with foreach:

Code:
<?php if (!empty($lastComments) && is_array($lastComments)) : ?>
    <?php foreach($lastComments as $comment): ?>
    <?php echo $comment['comment_text']; ?>
    <?php endforeach; ?>

<?php else : ?>
          <span>No comments</span>       
<?php endif; ?>


Unfortunately, however, it duplicates the results, oddly enough, since I use similar code to pick up other items without problems. Where am I wrong?
Reply
#2

I solved it like this:

PHP Code:
public function lastComments($limit){
        return $this->query('SELECT * FROM comments LIMIT '.$limit)
            ->getResult();
    


But I would still like to understand why he duplicated the results that way, does anyone have any ideas?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB