I am making student performance records in SQL. There are only 2 columns.
sl no. Name Points
1 Admam 89
2 Russel 86
3 Andy 79
4 Lance 76
5 Steve 75
6 jack 74
7 Phil 70
8 mark 67
9 kevin 65
10 andrew 65
11 brian 64
12 pat 63
This is SQL report format.. I need to colorize the table for every 3 students..For the first 3 student(1, 2, 3) called as 'Diamond' So that 3 rows needs to color Grey. Next 3 students (4,5,6) called as "platinum" so that 3 rows need to color green.
But in the next row, Phi, Mark, Kevin needs to color as Yellow. But Andrew also joining with Kevin because for same points. So now 4 rows should be colorize as yellow.. Please let me know how to do that....
look at this fiddle phpfiddle
<?php
$points=array(1,1,1,2,2,3,3,3,3);
$color= array(1=>'red',2=>'green',3=>'yellow');
?>
<table width="100%">
<?php
foreach($points as $key=>$grade)
{?>
<tr>
<td style="color:<?php if( $key!=0 && $points[$key]!=$points[$key-1] )
{echo $color[$grade];} else{ if(($key+1)%3==0)
{ echo $color[$grade];} else {echo $color[$grade];} } ?>">
student <?php echo $key; ?></td>
</tr>
<?php }?>
</table>
use a color for each range point like this
$colors = array(
1 => 'grey',
2 => 'green',
3 => 'yellow',
4 => 'black'
);
$i = 0;
$color_id = 0;
$lastpoint = -1;
foreach($students as $id=>$student) {
$color_id += ($i % 3 == 0 && $student['point'] != $lastpoint) ? 1 : 0;
$lastpoint = $student['point'];
?>
<tr>
<td style="color:<?php echo colors[$color_id];?>";>
<?php echo $student['name']; ?>
</td>
</tr>
<?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.