简体   繁体   English

在代码点火器中显示前10个结果,并显示第1,第2和第3个最高值

[英]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.

相关问题 显示1、2、3 ..最高排名到图库/幻灯片显示代码 - Display 1st,2nd,3rd.. top ranks to gallery/slideshow codeigniter 在php中显示当前星期的1、2、3、4和5日 - Display the 1st, 2nd, 3rd, 4th, & 5th date of the current week in php 从第2和第3个表中获取第1个表中匹配值的值 - Get the values from 2nd and 3rd table for the matched values in 1st table 我想在考试成绩中显示第 1、2、3 位 - I want to show position 1st, 2nd, 3rd in exam result MySQL - mysql日期格式后缀(第1,第2,第3 ......) - MySQL - mysql date format suffix (1st, 2nd, 3rd…) PHP日期和时间,在一个月内获得第1周,第2周,第3周和第4周 - PHP Date and Time, getting the 1st, 2nd, 3rd, and 4th week in a month 使用碳查找一周中的每一天 [1st,2nd,3rd] 对于接下来的 15 天 - Find every [ 1st,2nd,3rd ] day of week using carbon For next 15 day 如何确定星期几在一个月中的第一,第二,第三等发生? - How to determine if day of week is 1st, 2nd, 3rd, etc occurrence in a month? 我只想要第一个索引的值,然后是第二个索引,然后是第三个索引。 如何通过循环迭代并动态获取值? - I want only values of 1st index then 2nd and then 3rd index. How can I iterate through this with a loop and get the values dynamically? 如何改变 <option>第3个<select>基于第二次变化<select> ,其中第二个是通过使用jquery ajax更改第一个下拉列表的值来绘制的 - How to change <option> of a 3rd <select> based on change in 2nd <select>, where 2nd is drawn by changing value of 1st dropdown using jquery ajax
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM