I am using cakephp and here is my sample code below along with the css i am doing
<div class="thumbs">
<?php if(!empty($auction['Product']['Image']) && count($auction['Product']['Image']) > 0):?>
<?php foreach($auction['Product']['Image'] as $image):?>
<?php if(!empty($image['ImageDefault'])) : ?>
<span><?php
echo $html->link(
$html->image('default_images/'.$appConfigurations['serverName'].'/thumbs/'.$image['ImageDefault']['image']),
'/img/'.$appConfigurations['currency'].'/default_images/max/'.$image['ImageDefault']['image'],
array('class' => 'productImageThumb'),
null,
false);?>
</span>
<?php endif; ?>
<?php endforeach;?>
<?php endif;?>
</div>
.thumbs span //css for how to display the images
{
float:left;
width:75px; //this displays two images as a thumbnail in a single row
margin:12px;
border-right:1px solid #d5d5d5;
padding:3px;
}
My problem is i want to do css border-right:none for all the images having count as even numbers. I tried using for loop in the span of my code but not getting the result. Please suggest me how to dynamically do css border-right for only thumb images of odd number count and not for even numbers.
Add the key to the foreach loop and add a new class to odd images using the key (assuming this is a standard Cake query result where the key reliably increments by one):
(Protip: You don’t have to wrap every line of PHP into
<?php ... ?>tags. The code will be much more readable if you close the PHP tags only when you need to output pure HTML.)