简体   繁体   中英

Limit data to be display codeigniter view

I am currently developing a system. The system is all about posting events for 4 states/city and these 4 states, I displayed them using my tab panel. Then when I click the first tab(which is state 1),all the events of state 1 will be display. But there's a plot twist, if all the events is greater than 3, it will only shows 3 events then there will be a button "More" if not, it will just display the event.

Question: I am done everything except in the button part it display 3-4 times where it should be only 1 button will be display. Where should I place my button? Is my logic wrong?

View

<?php $ctr = 0;
      foreach($dejesus_events_result as $row):
        if($dejesus_events_count < 4){ ?>
        <?= $row->event_title;?>
        <?= $row->event_description;?>
<?php } else{ 
                while($ctr < 3){?>
            <?= $row->event_title;?>
            <?= $row->event_description;?>
            <?= $row->event_image;?>

                <?php $ctr++; } ?>
          <button class="btn btn-info"> More</button>
<?php } endforeach;?>

Then move button outside of loop

<?php $ctr = 0;
      foreach($dejesus_events_result as $row):
        if($dejesus_events_count < 4){ ?>
        <?= $row->event_title;?>
        <?= $row->event_description;?>
<?php } else{ 
                while($ctr < 3){?>
            <?= $row->event_title;?>
            <?= $row->event_description;?>
            <?= $row->event_image;?>

                <?php $ctr++; } ?>          
<?php } endforeach;?>

if($dejesus_events_count >= 4){ ?>
<button class="btn btn-info"> More</button>
<?php } ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM