Reputation: 21
<table width="100%">
<tr>
<?
$count=0;
$i=1;
foreach($gallery as $key => $list1)
{
$count++;
?>
<td>
<img src='<?echo base_url();?>userfiles/eventsgallery/small/<?=$list1['image'];?>'>
</td>
<? // style='background:red;'
if($count % 4 == 0 )
{
$color = "";
$i++;
if($i % 2 == 0)
{
$color = "style='background:orange;'";
}
else
{
$color = "style='background:black;'";
}
echo "</tr><tr ".$color.">";
}
}
?>
</tr>
Upvotes: 2
Views: 4214
Reputation: 179
If you would need to do it in your php loop, you can reverse your counter:
<?php
$count = count($gallery);
foreach($gallery as $key => $list1) {
$lastClass = $count == 1?' lastrow':'';
$count--;
?>
html here
<?php
}
?>
Upvotes: 0
Reputation: 9635
try this
<table width="100%" id="your_table_id">
<?
$count=0;
$i=1;
$size = sizeof($gallery);
foreach($gallery as $key => $list1) {
$count++;
$color = "";
if($size==$count) {
$color = "style='background:orange;'";
}
?>
<tr <?php echo $color;?>>
<td>
<img src='<?echo base_url();?>userfiles/eventsgallery/small/<?=$list1['image'];?>'>
</td>
</tr>
<?php
}
?>
</table>
OR you can Add a CSS Like this as @Mr. Alien answered
#your_table_id tr:last-child {
background: orange;
}
Upvotes: -1
Reputation: 557
Use :last-child
CSS
table tr:last-child {
background-color:#ccc;
}
Or
jQuery
$("table tr").last().css('background','#ccc')
I gave jQuery option too because :last-child
CSS selector has compatibility issue
Hope this is what you want
http://jsfiddle.net/HarishBoke/Xen99/
Upvotes: -1
Reputation: 127
...in css:
.table1 tr:last-child {
background-color: #0B615E;
}
<table width="100%" class="table1">
<tr>
<?
$count=0;
$i=1;
foreach($gallery as $key => $list1)
{
$count++;
?>
<td>
<img src='<?echo base_url();?>userfiles/eventsgallery/small/<?=$list1['image'];?>'>
</td>
<?
// style='background:red;'
if($count % 4 == 0 )
{
$color = "";
$i++;
if($i % 2 == 0)
{
$color = "style='background:orange;'";
}
else
{
$color = "style='background:black;'";
}
echo "</tr><tr ".$color.">";
}
}?>
</tr>
</tr>
</tr>
</table>
Upvotes: 0
Reputation: 157334
You can use CSS :last-child
pseudo to achieve that..
table.class_name tr:last-child {
background: #f00;
}
Upvotes: 4