处理复选框PHP [英] handling checked checkboxes PHP
本文介绍了处理复选框PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个从数据库中取数据的表格:(不是表单)
I have a table that takes data from the database like so: (Is not a form)
if (mysql_num_rows($result)) {
echo "<table id='logs' border='1' cellspacing='0' width='62%'>";
echo "<tr>";
echo "<th width='15%'>Time Registered</th>";
echo "<th width='15%'>Username</th>";
echo "<th width='15%'>Password</th>";
echo "<th width='15%'>IP Address</th>";
echo "<th width='2%'><a href=\"#\" onclick=\"checkAll(this);\">Mark</a></th>";
echo "<th width='2%'>Delete</th>";
echo "</tr>";
while ($row = mysql_fetch_row($result))
{
echo "<tr>";
echo ("<p><td>$row[2]</td><td>$row[0]</td><td>$row[1]</td><td><i>$row[3]</i></td><td><center><input type=\"checkbox\" name=\"mark[]\"/></center></td><td><a href=\"delete.php?time=$row[2]&user=$row[0]&pass=$row[1]&ip=$row[3]\"><center>[x]</center></a></td></p>");
echo "</tr>";
}
echo "</table>";
}
部分< input type = \ checkbox\name = \mark [] \/>
是复选框。如何找到并处理选中的复选框?
The part <input type=\"checkbox\" name=\"mark[]\"/>
is the checkbox. How can I find and handle the checked checkboxes?
if(mark[$checked]) {
//delete data from database if row checked
}
推荐答案
foreach($_REQUEST['mark'] as $value){
echo "$value was selected\n <br />";
}
如果您想知道哪一个未被选择,
if you want to know which one wasn't selected then store all possible selections into an array and walk ofer this array and do someting like
foreach($poss_select as $key=>$val){
if(!in_array($val,$_REQUEST['mark']){
$not_selected[$key] = $value;
}else{
deleteRow($value);
}
}
这篇关于处理复选框PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文