doufeikuang7724 2014-12-01 14:42
浏览 21
已采纳

学生的成绩与他们在课堂上的位置

I need help on this script, I printed out the student result and try to get their position in class.

<html>
<body>
<table border="0" cellspacing="1" cellpadding="0">
<tr>
<td><p align="center"><strong>Student     Name</strong></p></td>
<td><p align="center"><strong>Computer</strong></p></td>
<td><p align="center"><strong>Position</strong></p></td>
</tr>
<tr>
<td><p>Agbo Cynthia </p></td>
<td><p>21.0</p></td>
<td><p> </p></td>
</tr>
<tr>
<td><p>Nwoye Ugochukwu </p></td>
<td><p>76.0</p></td>
<td><p></p></td>
</tr>
<tr>
<td><p>Ogburie Kosisochukwu </p></td>
<td><p>28.0</p></td>
<td><p> </p></td>
</tr>
<tr>
<td><p>Okechukwu Onyeka </p></td>
<td><p>38.0</p></td>
<td><p> </p></td>
</tr>
</table>
</body>
</html>

Having try scripts to determine the student position base on their score that have in db, I could not eventually get the right script. I make use of this scripts bellow, but it repeating scores value.

$row['comp'] is the scores from each student from db

<?php
$grades = array(''.$row['comp'].'');
$occurrences = array_count_values($grades);
$grades = array_unique($grades);
foreach($grades as $grade) 
   {
echo str_repeat($grade .' - '.($i+1).'<br>',$occurrences[$grade]);
$i += $occurrences[$grade];
   }
?>

What I want is a script that will give the student in the class their position according to the computer score in db

  • 写回答

2条回答 默认 最新

  • dongzhun4898 2014-12-01 14:47
    关注

    When you use an OR (||) you cannot only check the second value, you need to recheck each element. (Example)

    if($a == $b || $a == $c)
    

    Can you force like this?

    if (substr($pross['posi'], -1) == 1 && $pross['posi'] != 11){
         echo $pross['posi'].'st';
    } elseif(substr($pross['posi'], -1) == 2 && $pross['posi'] != 12){
         echo $pross['posi'].'nd';
    } else {
         echo $pross['posi'].'th';
    }
    

    I'm forcing the value to string, then i check the last value of each string.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 TeleScan不能修改bar
  • ¥100 请问我基于逐飞库写的这个有关于mp u6050传感器的函数,为什么输出的值是固定的?
  • ¥15 hadoop中启动hive报错如下怎么解决
  • ¥15 如何优化QWebEngineView 加载url的速度
  • ¥15 关于#hadoop#的问题,请各位专家解答!
  • ¥15 如何批量抓取网站信息
  • ¥15 Spring Boot离线人脸识别
  • ¥15 使用Ant Design Pro vue的时候,使用环境变量的时候,构建报错是什么原因
  • ¥15 NRF24L01能发送但是不能接收
  • ¥15 想问一下这种情况怎么解决呢(关键词-file)