[英]Display top 10 results in codeigniter and display 1st, 2nd and 3rd top values
I am getting output page like this (Shown in below screenshot 我正在得到这样的输出页面(如下面的屏幕截图所示)
)
)
I want gold image to be display to top scorers and silver to second topper and bronze to others 我希望向得分最高的人显示金色图像,向第二名的顶部显示银色图像,向其他人显示古铜色
I am using code like this 我正在使用这样的代码
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><i class="fa fa-tasks"></i> ScoreBoard</h3>
</div>
<div class="panel-body">
<div class="col-sm-12">
<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered">
<tbody>
<?php
$total_exams1 = $this->db->select('title_id')
->from('exam_title')
->count_all_results();
$b1 = $this->db->select('*, (sum(result.result_percent)) / '.$total_exams1.' as percent')
->group_by('users.user_id')
->from('result')
->order_by("percent", "desc" )
->join('users', 'users.user_id = result.user_id', 'left')
->join('states', 'users.state = states.state_id', 'left')
->join('user_zone', 'users.user_zone = user_zone.user_zone_id', 'left')
->limit("10")
->get()
->result();
$j = 1;
foreach($b1 as $z) {
?>
<tr class="<?= ($i & 1) ? 'even' : 'odd'; ?>">
<td style="width:5%;"><?php echo $j; ?></td>
<?php if($z->image == "") { ?>
<td class="hidden-x" style="width:35%;">
<img class="userImgTop10n" src="<?php echo base_url('user-avatar/avatar-placeholder.jpg') ?>" alt="Profile Picture" />
<div class="image_righ">
<b><?php echo $z->user_name; ?></b><br>
<?php echo $z->state_name; ?><br>
<?php echo $z->user_zone_name; ?>
</div>
</td>
<?php } else { ?>
<td class="hidden-x" >
<img class="userImgTop10n" src="<?php echo base_url("user-avatar/".$z->image); ?>" alt="Profile Picture" />
<div class="image_righ">
<b><?php echo $z->user_name; ?></b><br>
<?php echo $z->state_name; ?><br>
<?php echo $z->user_zone_name; ?>
</div>
</td>
<?php } ?>
<?php
$exams_attended1 = $this->db->select('title_id')
->where('user_id', $z->user_id)
->from('result')
->group_by('user_id')
->count_all_results();
?>
<td class="hidden-xxs"><b><?php echo $exams_attended1; ?></b><br>Exams Attended</td>
<td class="hidden-xxs"><b><?php echo $total_exams1; ?></b><br>Total Exams</td>
<td class="hidden-x">
<b><?php echo round($z->percent, 2); ?> %</b><br>Avg Result
<div class="badge_righ">
<?php if($j == 1) { ?>
<span><img class="userBadge" src="<?php echo base_url('Badge_Gold.png') ?>" alt="Badge Gold" /></span>
<?php }
if($j == 2) { ?>
<span><img class="userBadge" src="<?php echo base_url('Badge_Silver.png') ?>" alt="Badge Gold" /></span>
<?php } if($j > 2) { ?>
<span><img class="userBadge" src="<?php echo base_url('Badge_Bronze.png') ?>" alt="Badge Gold" /></span>
<?php } ?>
</div>
</td>
</tr>
<?php
$j++;
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
in the above screenshot first 3 rows should be gold images (because of same marks). 在上面的屏幕截图中,前三行应为金色图像(由于相同的标记)。
You can create a temporary array containing unique reverse sorted average scores. 您可以创建一个临时数组,其中包含唯一的反向排序的平均分数。 Then, when giving medals, instead of checking for places (1st, 2nd, 3rd...), check if the score matches the 1st, 2nd or 3rd score from that temporary array.
然后,在颁发奖牌时,不要检查位置(第一,第二,第三...),而是检查分数是否与该临时数组中的第一,第二或第三分数匹配。
For the screenshot you posted, the array would look like: 对于您发布的屏幕截图,数组如下所示:
$scores = [92.5, 90, 87.5];
and the gold medals would be all the scores with the score of $scores[0]
, the silver ones are $scores[1]
and the bronzes would be $scores[2]
(unless you want everyone else to get bronze). 金牌将是分数为
$scores[0]
所有分数,银牌为$scores[1]
,铜牌为$scores[2]
(除非您希望其他所有人都获得铜牌)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.