我正在编写此代码以插入出勤。这段代码很好。但是有一些输出我不希望它再次出现两次。我不知道我到底需要在哪里更正它。希望有人可以重新排列我的代码,以便输出不会像下面的图片。
$class = getfield('class');
$getdata = mysql_query("select * from student where class = '$class' order by name ") or die(mysql_query);
$result = "select birth_no from student where class = '$class'";
$getbirth = mysql_query($result) or die(mysql_error());
if(isset($_POST['date']))
{
$_SESSION['date'] = $_POST['date'];
$date = $_POST['date'];
if(!empty($date))
{
while($row = mysql_fetch_assoc($getdata))
{
$id = $row["birth_no"];
$query = "SELECT * FROM attendance WHERE date = '$date' and birth_no = '$id'";
$query_run = mysql_query($query);
if(mysql_num_rows($query_run)==0)
{
//start now
//start here
if (isset($_POST['submit']))
{
if(isset($_POST['a'.$id])) {
$status = $_POST['a'.$id];
if(!empty($status)){
if(($status == "present" || $status == "mc")){
$attend = 1;
}
else {
$attend = 0;
}
$query = "INSERT INTO attendance(ID, birth_no, date, status, attend)
VALUES ('', '$id','$date','$status','$attend')";
if($query_run = mysql_query($query)){
echo 'Insert attendance done';
}
else{
echo'Attendance not inserted.';
}
}
else{
echo 'Please enter all fields';
}
}
}
else
{
?>
<form action="addattend1.php" method = "POST">
<?php
$name = $row['name'];
?>
<tr>
<td><center><?php echo $date ?></center></td>
<td><center><?php echo $id ?></center></td>
<td><center><?php echo $name ?></center></td>
<td><center>
<input type="radio" name="a<?php echo $id; ?>" value="present"/>PT
<input type="radio" name="a<?php echo $id; ?>" value="absent"/>AT
<input type="radio" name="a<?php echo $id; ?>" value="mc"/>MC
</center>
</td>
</tr>
<?php
} // end else
?>
<?php //end here
}//end if
else
{
echo '<br><br>Attendance for date <font color="#FF0000" ><b><u>'.$date.'</u></b></font> is already inserted!<br><br>';
}
}//end while
?>
</table>
<br /><br />
<center><input type="submit" name="submit" value="Submit"></center><br /><br />
</form> <!-- end the form here -->
<?php
}//if not empty
else
{
?>
<br/
<font size="3" color color="#FF0000"><?php echo 'Please pick a date first before proceed!' ?> </font><br>
<?php
}
}//if isset date
else
{
?><br/><br/>
<form action="addattend.php" method = "POST">
Date :<br><br ><input type="date" name = "date">
<input type="submit" value="Submit"><br /><br />
</form> <?php
}
如上图所示,由于有 2 个学生,因此出现了两次“已插入日期的出勤”。如果有 5 个学生,则该字符串将出现 5 次,依此类推。我真正想要的是,我希望它只出现一次,并且带有提交按钮的表格不会显示在那里。
请帮我。谢谢你。