att_id
s_no
std_reg_no
std_name
semester_id
total_classes
present
absent
我已经制作了这个表格,其中显示了特定学期的学生和用于标记学生是否在场的单选按钮。我通过数组使用了无线电名称中的s_no学生代码
<form method="POST" enctype="multipart/form-data" >
<input type="hidden" name="chk" value="update">
<table border="groove" cellpadding="15px">
<tr>
<td>s.no</td>
<td>Reg. No</td>
<td>name</td>
<td>Present</td>
</tr>
<?php
while ($row = mysql_fetch_assoc($rs)){
$id= $row['s_no'];
$no[]= $row['std_reg_no'];
echo "<tr><td>";
echo $row['s_no']."</td><td>";
echo $row['std_reg_no']."</td><td>";
echo $row['std_name']."</td>";
echo "<td> <input type='radio' name='attend[$id]' value='present' >Present <input type='radio' name='attend[$id]' value='ab'>absent</td></tr>";
}
echo "</table>";
echo "<input type='submit' name='btnAbsent' value='submit'>";
echo a;
?>
</form>
我想在php中做的是将每个radiobutton(如果存在)添加+1以呈现并且如果不存在+!请不要有人帮忙
答案 0 :(得分:0)
试试这个,如果你选择任何人作为礼物,我增加+1,如果你选择任何人作为缺席,我减少-1 ...
数据库表结构查询
CREATE TABLE IF NOT EXISTS `attendance` (
`att_id` varchar(255) NOT NULL,
`s_no` varchar(255) NOT NULL,
`std_reg_no` varchar(255) NOT NULL,
`std_name` varchar(255) NOT NULL,
`semester_id` varchar(255) NOT NULL,
`total_classes` varchar(255) NOT NULL,
`present` int(255) NOT NULL DEFAULT '0',
`absent` int(255) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
<form method="POST" enctype="multipart/form-data" >
<input type="hidden" name="chk" value="update">
<table border="groove" cellpadding="15px">
<tr>
<td>s.no</td>
<td>Reg. No</td>
<td>name</td>
<td>Present</td>
</tr>
<?php
include_once("yourconfig.php"); //add here your db config file
extract($_POST);
//After Click on Submit Call this
if(isset($btnAbsent))
{
foreach($attend as $atn_key=>$atn_value)
{
if($atn_value=="present")
{
$upd_qry="UPDATE attendance SET present=present+1 where s_no='".$atn_key."'";
mysql_query($upd_qry);
}
elseif($atn_value=="absent")
{
$upd_qry="UPDATE attendance SET absent=absent-1 where s_no='".$atn_key."'";
mysql_query($upd_qry);
}
}
}
//Default call this
$check_exist_qry="select * from attendance";
$rs=mysql_query($check_exist_qry);
$total_found=mysql_num_rows($rs);
while ($row = mysql_fetch_assoc($rs))
{
$id= $row['s_no'];
$no[]= $row['std_reg_no'];
echo "<tr><td>";
echo $row['s_no']."</td><td>";
echo $row['std_reg_no']."</td><td>";
echo $row['std_name']."</td>";
echo "<td> <input type='radio' name='attend[$id]' value='present' >Present <input type='radio' name='attend[$id]' value='absent'>absent</td></tr>";
}
echo "</table>";
echo "<input type='submit' name='btnAbsent' value='submit'>";
?>
</form>
如果您发现这是一个有用的方法,请将此答案作为正确答案,并对此解决方案进行投票