Php 使用表在codeigniter视图中显示ind数据 您好,我在为学生排序正确的科目结果时遇到问题。我在学校开设了11门课程,高年级学生选修了8门课程,因为这一级别有4门选修课。因此,当为高年级学生获取结果并在学生不学习该科目时显示结果时,它仍然会在错误的字段中回显结果。我下面的代码不区分,例如,是物理还是生物。

Php 使用表在codeigniter视图中显示ind数据 您好,我在为学生排序正确的科目结果时遇到问题。我在学校开设了11门课程,高年级学生选修了8门课程,因为这一级别有4门选修课。因此,当为高年级学生获取结果并在学生不学习该科目时显示结果时,它仍然会在错误的字段中回显结果。我下面的代码不区分,例如,是物理还是生物。,php,html,html-table,tablerow,Php,Html,Html Table,Tablerow,我想让它与一个(-)相呼应,学生不选修这个科目。提前谢谢 Hi am having problem in sorting the correct <td> to display subject results for students. i have 11 subjects offered in the school and senior students take 8 subjects because 4 are electives at this level. so when f

我想让它与一个(-)相呼应,学生不选修这个科目。提前谢谢

Hi am having problem in sorting the correct <td> to display subject results for students. i have 11 subjects offered in the school and senior students take 8 subjects because 4 are electives at this level. so when fetching results for the senior students and displaying when the student does not take that subject it still echoes the result in the wrong field.my code below does not distinguish e.g if the <td> is physics or biology.

职位学生英语基斯瓦希里数学地理物理化学历史地理知识农业商业总分数平均分数聚合点位置

上述代码起作用,但在错误的表格数据字段中显示了学生完成的主题。使用主题代码识别主题,如英语是101,斯瓦希里语是102,数学是121。我可以看出主题是静态的。我希望你有一个结果的数据结构,根据学生id和课程id建立适当的关系。然后你可以循环所有结果并获取相关的科目名称和学生名称。eg

<table border='1'>
        <tr><th>Position</th><th>Students</th><th>English</th><th>Kiswahili</th><th>Maths</th><th>Biology</th><th>Physics</th><th>Chemistry</th><th>History</th><th>Geography</th><th>CRE</th><th>Agriculture</th><th>Business</th><th>Total Marks</th><th>Mean Grade</th><th>Aggregate Points</th><th>Action</th>
        </tr> 
        <?php
//loop to display the names of students
        $i = 1;
        foreach ($overallresults as $result) {
            echo "<tr>";
            echo "<td>";                
        echo $i++;
        echo "</td>";
        $admNo = $result->admNo;
        $total_marks = $result->total_marks;
        $agp = $result->aggregate_points;
        $mean_grade = $result->mean_grade;
        $agp = $result->aggregate_points;
        $result_id = $result->result_id;
        $fname = "";

        foreach ($students as $student) {
            // print_r($student);
            $admNo1 = $student->admNo;
            if ($admNo == $admNo1) {
                // print_r($student);
                $fname = $student->firstName;
                $mname = $student->middleName;
                $lname = $student->lastName;
                //}
                // }
                //echo "<tr>";

                echo "<td>";
                echo $fname . " " . $mname . " " . $lname;
                echo "</td>";
            }
        }   

        foreach ($subjectresults as $subresult) {
            // print_r($result); 
            $score = "0";
            $admNo3 = $subresult->admNo;
            $subCode = $subresult->subCode;
            $score = $subresult->score;

            if ($admNo == $admNo3) {
                if ($subCode == '232') {
                    $score = $score;
                }
                if ($subCode == '101') {
                    echo "<td>";
                    echo $score;
                    echo "</td>";
                }


                if ($subCode == '102') {
                    echo "<td>";
                    echo $score;
                    echo "</td>";
                }
                if ($subCode == '121') {
                    echo "<td>";
                    echo $score;
                    echo "</td>";
                }
                if ($subCode == '231') {
                    echo "<td>";
                    echo $score;
                    echo "</td>";
                }
                if ($subCode == '232') {
                    echo "<td>";
                    echo $score;
                    echo "</td>";
                }

                if ($subCode == '233') {
                    echo "<td>";
                    echo $score;
                    echo "</td>";
                }
                if ($subCode == '311') {
                    echo "<td>";
                    echo $score;
                    echo "</td>";
                }
                if ($subCode == '312') {
                    echo "<td>";
                    echo $score;
                    echo "</td>";
                }
                if ($subCode == '313') {
                    echo "<td>";
                    echo $score;
                    echo "</td>";
                }
                if ($subCode == '443') {
                    echo "<td>";
                    if (!$score) {
                        echo 0;
                    } else {
                        echo $score;
                    }
                    echo "</td>";
                }
                if ($subCode == '565') {
                    echo "<td>";
                    echo $score;
                    echo "</td>";
                }
            }
        }
            ?>


        <?php
        if (isset($term)) {
            $term = $term;
        }
        if (isset($form)) {
            $form = $form;
        }

        if (isset($year)) {
            $year = $year;
        }
        if (isset($examCategory)) {
            $examCategory = $examCategory;
        }

        //if ($admNo == $admNo1) {
        // print_r($student);
        //}
        // }

        echo "<td>";
        echo $total_marks;
        echo "</td>";
        echo "<td>";
        echo $mean_grade;
        echo "</td>";
        echo "<td>";
        echo $agp;
        echo "</td>";
        echo "<td>";

        echo "</td>";

        //}
    }
    ?>

    </table>
    <?php
}
?>
</div>


当然,您必须编写助手函数来获取学生姓名和计算平均分数。

谢谢。这没关系,您已经为单个学生完成了它的工作。我知道需要一种显示所有参加考试的学生的情况。因此,学生的科目不同,其他字段应为空或有(u)我如何确保它跳过a并在确切字段中回显我已编辑代码。它完全按照您的要求运行,您可以在此处进行测试:
<?php
$results = array();
$subjects = array(101=>"English", 102=>"Kiswahili",103=>"Physics",104=>"Chemistry");
$students = array("tom","dick","ally");
$result1 = array(
'studentId'=>1,
'score'=>array(
      101=>20,
      102=>30,
      103=>30,
      104=>45
),);

$result2 = array(
'studentId'=>2,
'score'=>array(
      101=>34,
      102=>54,
      103=>77
),);
$results[] = $result1;
$results[] = $result2;
echo "<table border='1'>";
echo "<tr>";
echo "<th>#</th><th>Student</th>";
for($i = 101; $i < 105; $i++){
echo "<th>".$subjects[$i]."</th>";
}
echo "</tr>";
$count = 1;
foreach($results as $result){

echo "<tr>";
echo "<td>".$count."</td>";
echo "<td>".$students[$result['studentId']]."</td>";
foreach($subjects as $key => $value){
$marks = $result['score'][$key]!=null?$result['score'][$key]:'-';
echo "<td>".$marks."</td>";
}
echo "</tr>";
$count++;
}
echo "</table>";
?>