$delete = $_POST['delete']; // POST方式獲得復(fù)選框值
網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)!專注于網(wǎng)頁(yè)設(shè)計(jì)、網(wǎng)站建設(shè)、微信開(kāi)發(fā)、小程序定制開(kāi)發(fā)、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項(xiàng)目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了九原免費(fèi)建站歡迎大家使用!
//單擊刪除按鈕時(shí)
if ($submitdel) // 按提交按鈕
{
//以,號(hào)組合成字符串,供mysql使用
$aryid=@implode(",",$delete);
$db-query("delete from `table` where id in($aryid)");
}
復(fù)選框的大致代碼:
input type="checkbox" name="delete[]" value="?php echo $id; ?"
原理:復(fù)選框的name屬性為delete[] 所以選擇如果個(gè)之后獲得的$delete值為一個(gè)數(shù)組,例如是$delete = array(0 = 1,1 = 2,2 = 3);
然后用implode函數(shù)將數(shù)組切割成字符串,$aryid=@implode(",",$delete);那么$aryid就是 $aryid = "1,2,3";
然后執(zhí)行sql語(yǔ)句。delete from `table` where id in($aryid)
SQL語(yǔ)句就是delete from `table` where id in(1,2,3);
這樣就很明白了吧
為刪除按鈕增加一個(gè)sub句柄name=del,$_POST['sub']按鈕觸發(fā)sql處理刪除數(shù)據(jù)庫(kù)中的數(shù)據(jù),
我只能提供思想,實(shí)際問(wèn)題實(shí)際對(duì)待。不懂的可以繼續(xù)問(wèn)我。
1、首先在視圖頁(yè)面找到要?jiǎng)h除的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、寫(xiě)一個(gè)delete.php頁(yè)面,代碼如下:
?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);
?
說(shuō)明:用于MySQL數(shù)據(jù)刪除的SQL語(yǔ)句為:
delete from 表名 where 條件=值
這里的值通過(guò)$del_id=$_GET["id"]來(lái)接收,并傳遞給SQL語(yǔ)句,最后通過(guò)mysql_query來(lái)執(zhí)行這句SQL語(yǔ)句刪除的。
!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
價(jià)格
/th
th
數(shù)量
/th
th
小計(jì)
/th
/tr
tr
td
合計(jì):
/td
td?colspan=3?id="heji"
/td
/tr
/table
/div
/body
/html