我正在用php设计一个考勤模块。要使用 php 中的单选按钮标记出勤情况,我正在使用表单并将其发布到其他网页。
表格代码:-
<form method="POST" action="marked.php">
<p align="center">
<center><h2>Your Subject Students</h2></center>
<?php
$link=mysql_connect("mysql4.000webhost.com","a2101142_jxpolre","jxplor1") or die("Cannot Connect to the database!");
mysql_select_db("a2101142_login",$link) or die ("Cannot select the database!");
$query="SELECT sid,sname FROM studentdetails s,facultydetails f WHERE ( s.sub1=f.subid OR s.sub2=f.subid OR s.sub3=f.subid) AND f.fid=$id";
$resource=mysql_query($query,$link);
echo "<table align='"center'" border='"0'" width='"70%'">
<tr><td><b>S.No.</b></td> <td><b>Student ID</b></td> <td><b>Name</b></td> <td><b>Present</b></td> <td><b>Absent</b></td></tr> ";
$x=0;
while($result=mysql_fetch_array($resource))
{ $x++;
echo "<tr><td>".$x."</td><td>".$result[0]."</td><td>".$result[1]."</td><td><input type='radio' name='attend[$result[0]]' value='Present'></td><td><input type='radio' name='attend[$result[0]]' value='Absent'></td></tr>";
} echo "</table>";
?>
<center><input type='submit' name='Submit' value='Submit'>   <input type="reset" value="Reset"/></center>
</form>
标记.php代码:-
<?php
print_r($_POST);
?>
在这里我正在接收输出:-阵列 ( [出席
] => 阵列 ( [2202] => 当前 [2203] => 当前 [2204] => 当前 [2208] => 当前 [2210] => 当前 [2211] => 当前 [2216] => 当前 [2217] => 当前 [2218] => 当前 ) [提交] => 提交 )如何将$id和存在/不存在与 $_POST()??请帮忙????/
使用foreach
来实现这一点。
foreach($_POST['attend'] as $id => $staus){
echo $id; //will print 2202
echo $status; // will print Present
}
希望这对:)有所帮助