我有一个作业,其表格以 ID 和姓氏作为输入。我想同时获取 ID 和姓氏并将其与文本文件匹配。如果匹配,请在表格中显示该学生。如果不匹配,则回显未找到学生。到目前为止,我几乎完成了所有工作,但每次搜索存在的学生时,都会回显未找到的学生。
这是我的表格的链接:http: //hills.ccsf.edu/~ryan/a7p1.php
这是您可以从中获取 ID 和姓氏的学生班级。第一列是学生 ID,第二列是姓氏: http: //fog.ccsf.edu/~tboegel/showclass.php
这是代码:
<?php
$lname = $_REQUEST['lname'];
$id = $_REQUEST['id'];
function DisplayRow($ID) {
print "<tr>\n";
$parts = split(":", $ID);
for($i=0; $i <=7; $i++) {
print "<td>$parts[$i]</td>\n";
}
print "</tr>\n";
}
$handle = fopen("class.txt", "r");
$line = fgets($handle);
while(!feof($handle)) {
$part = explode(":", $line);
if($id == $part[0] && $lname == $part[1]) {
echo "<table border='1' width='95%'>
<tr>
<th>Student ID</th>
<th>Student Last Name</th>
<th>Student First Name</th>
<th>Midterm 1</th>
<th>Midterm 2</th>
<th>Midterm 3</th>
<th>Final Exam</th>
<th>Letter Grade</th>
</tr>";
DisplayRow($line);
} else {
print "The person you are trying to search for does not exist";
die;
}
$line = fgets($handle);
}
fclose($handle);
print "</table>\n";
?>