dongying3744 2011-03-30 17:21
浏览 48
已采纳

处理已检查的复选框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>";
}

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
}
  • 写回答

3条回答 默认 最新

  • dqrnskni67375 2011-03-30 17:25
    关注
    foreach($_REQUEST['mark'] as $value){
        echo "$value was selected
     <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);
        }
    } 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100