$delete = $_POST['delete']; // POST方式获得复选框值
网站建设哪家好,找创新互联!专注于网页设计、网站建设、微信开发、小程序定制开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了九原免费建站欢迎大家使用!
//单击删除按钮时
if ($submitdel) // 按提交按钮
{
//以,号组合成字符串,供mysql使用
$aryid=@implode(",",$delete);
$db-query("delete from `table` where id in($aryid)");
}
复选框的大致代码:
input type="checkbox" name="delete[]" value="?php echo $id; ?"
原理:复选框的name属性为delete[] 所以选择如果个之后获得的$delete值为一个数组,例如是$delete = array(0 = 1,1 = 2,2 = 3);
然后用implode函数将数组切割成字符串,$aryid=@implode(",",$delete);那么$aryid就是 $aryid = "1,2,3";
然后执行sql语句。delete from `table` where id in($aryid)
SQL语句就是delete from `table` where id in(1,2,3);
这样就很明白了吧
为删除按钮增加一个sub句柄name=del,$_POST['sub']按钮触发sql处理删除数据库中的数据,
我只能提供思想,实际问题实际对待。不懂的可以继续问我。
1、首先在视图页面找到要删除的id:
?php
$link=mysql_connect("localhost","root","管理员密码");
mysql_select_db("infosystem", $link);
$q = "SELECT * FROM info";
mysql_query("SET NAMES GB2312");
$rs = mysql_query($q, $link);
echo "table";
echo "trtd部门名称/tdtd员工姓名/tdtdPC名称/td/tr";
while($row = mysql_fetch_object($rs)) echo "trtda href='dodel.php?id=$row-id'del/a/tdtd$row-depart/tdtd$row-ename/td/tr";
echo "/table";
?
2、写一个delete.php页面,代码如下:
?php
$link =mysql_connect("localhost","root","管理员密码");
mysql_select_db("infosystem", $link);
$del_id=$_GET["id"];
$exec="delete from info where id=$del_id";
mysql_query($exec, $link);
echo "删除成功!";
mysql_close($link);
?
说明:用于MySQL数据删除的SQL语句为:
delete from 表名 where 条件=值
这里的值通过$del_id=$_GET["id"]来接收,并传递给SQL语句,最后通过mysql_query来执行这句SQL语句删除的。
!DOCTYPE html
html
head
meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
title
RunJS 演示代码
/title
style
*{
margin:0;
padding:0;
}
.wrap{
margin:auto;
width:800px;
font: bolder 16px 'Comic Sans MS' '新宋体';
}
.wrap [name=sp]{
border: 1px solid black;
width: 200px;
height: 50px;
text-align:center;
line-height:50px;
margin:10px;
}
.wrap [name=sp]:hover{
background-color:#fd3;
cursor:pointer;
}
.wrap .shu{
width:0px;
height: 311px;
border: 1px solid black;
margin: -121px auto auto 231px;
}
.wrap table {
margin: -311px auto auto 291px;
border:1px solid black;
border-collapse:collapse;
width: 300px;
}
.wrap table th {
background-color: gray;
color:white;
}
.wrap table th, td{
border:1px solid black;
text-align:center;
}
/style
script
var info = [["商品1",50],["商品2",100]];
onload = function(){
var tbody = table.tBodies[0];
var sps = document.getElementsByName("sp");
var fun = function(i){
sps[i].onclick = function () {
for(var k = 0; k tbody.rows.length; k++){
var r = tbody.rows[k];
var tds = r.cells;
for(var j = 0; j tds.length;j++){
if(tds[j].innerHTML.indexOf(info[i][0])!=-1){
tbody.deleteRow(r.rowIndex);
break;
}
}
}
var tr = tbody.insertRow(tbody.rows.length - 1);
var io = info[i];
for(var j = 0; j 4; j++){
var td = tr.insertCell(tr.cells.length);
if(j==2){
!io[j] ? io[j] = 1 : io[j]++;
}else if(j==3){
!io[j] ? io[j] = io[1] : sum+=(io[j]+=io[1]);
}
td.innerHTML = io[j];
}
var sum=0;
for(var k=0;kinfo.length;k++){
var ik =info[k][3];
if(ik) sum+=ik;
}
heji.innerHTML = sum;
}
}
for(var i = 0; i sps.length; i++) {
fun(i);
}
document.onselectstart = new Function("return false");
}
/script
/head
body
div class="wrap"
div name="sp"
商品1nbsp;¥50
/div
div name="sp"
商品2nbsp;¥100
/div
div class="shu"
/div
table id="table"
tr
th
名称
/th
th
价格
/th
th
数量
/th
th
小计
/th
/tr
tr
td
合计:
/td
td colspan=3 id="heji"
/td
/tr
/table
/div
/body
/html