首页 > 解决方案 > 检查学生是否正在上课

问题描述

这是我的代码。我想检查学生是否正在上课。现在它应该显示哪个学生没有上课时会打印“No student with that id”。

<?php
    $students = "students.txt";
    $id = $_GET['student'];
    $line = file($students);
    $i=0;
    $string_line_array = explode('|', $line[0]);

    $fp=@fopen($students, r);
    if(is_resource($fp))
    {
        while(@!fgets($line[$i]))
        {
            $string_line_array = explode('|', $line[$i]);
            if($string_line_array[0] == $id)
            {
                if($string_line_array[2] == 0)
                {
                    echo $string_line_array[1]."(".$string_line_array[0]."): "."hasn\'t signed up";
                    break;
                }
                else
                {
                    echo $string_line_array[1]."(".$string_line_array[0]."): "."has signed up";
                    break;
                }
            }
            else
            {
                echo "No students with that id!";
            }
            $i++;
        }
    }
    else
    {
        echo "Error!";
    }
?>

标签: php

解决方案


推荐阅读