lundi 30 septembre 2019

Loop statement inside if else statement

i want to show all rows using loop in a table, but if there is no data available i want to echo some text there. i am using codeigniter. i want to use loop inside if statement and in else i will echo any text when there will be no data.

here is the code

<?php 
$nextdate = date('Y-m-d',strtotime("+3 day"));
$this->db->order_by('tourdateID', 'ASC');
$this->db->where('tourid', $blogres[0]['tourid']);
$this->db->where('start >=', $nextdate); 
$subs = $this->db->get('tour_date')->result_array();

$i = 1;

foreach($subs as $sub){?>
    <div class="row priceRow priceRowReg  filter_12  guaranteedFlag">
        <div class="eq-pr2 small-4 medium-4 large-4 columns pad-lft-20">
            <div class="tcircle amber"></div><a class="date drk" rel="nofollow" href="#"><?php echo date('d M, Y', strtotime($sub['start'])); ?> - <?php echo date('d M, Y', strtotime($sub['end'])); ?></a>

        </div>

        <div class="eq-pr2 small-3 medium-3 large-3 columns cnt bld"><?php 

        $this->db->where('tourdateID',$sub['tourdateID']);
        $booking = $this->db->count_all_results('book_tour');                    
        $availibility = $sub['total_capacity'] - $booking;


        ?><?= $availibility; ?> Seats left</div>
        <div class="eq-pr2 small-3 medium-3 large-3 columns cnt pad-rgt-20"><a class="inl bld f19 wht wrBCol3 colLinkPad showinfo" rel="nofollow" href="<?=base_url();?>bookings/step1/<?= $blogres[0]['tourid'];?>/<?= $sub['tourdateID']?>">Book Now</a> </div>

    </div>

<? } ?>

Aucun commentaire:

Enregistrer un commentaire