Reputation: 1
I have two images in a folder and their record is in a database so I want to show the images on the page through a for loop. But the problem is that I have classes (left and right) for which I want to define a variable to show images separately, so how can I do. The only problem is with the $val
variable.
<div class="col-md-7 wthree-services-bottom-grids">
<?php for ($i = 0; $i < 2; $i++){ $val = ''?>
<div class="wthree-services-<?php echo $val; ?>">
<img src="<?php echo base_url(); ?>uploads/frontend/about_us/<?php echo $about_images[$i]->image; ?>" alt="">
</div>
<?php $val = 'right'; }?>
<!-- <div class="wthree-services-right">
<img src="<?php echo base_url(); ?>uploads/frontend/about_us/<?php echo $about_images[1]->image; ?>" alt="">
</div>-->
<div class="clearfix"> </div>
</div>
Upvotes: 0
Views: 50
Reputation: 1826
I'm not sure if I understand correctly what you're trying to do but does this behave like what you're after?
<div class="col-md-7 wthree-services-bottom-grids">
<?php
for ($i = 0; $i < 2; $i++):
$val = ($i == 0 || $i % 2 == 0 ? 'left': 'right'); ?>
<div class="wthree-services-<?php echo $val; ?>">
<img src="<?php echo base_url(); ?>uploads/frontend/about_us/<?php echo $about_images[$i]->image; ?>" alt="">
</div>
<div class="clearfix"></div>
<?php endfor; ?>
Upvotes: 1