php批量刪除操作(數(shù)據(jù)訪問(wèn))
本文實(shí)例為大家分享了php批量刪除操作的具體代碼,供大家參考,具體內(nèi)容如下

1.批量刪除頁(yè)面 piliangcaozuo.php
<body>
<form action="shanchu.php" method="post">
<table width="100%" border="1" cellpadding="0" cellspacing="0">
<tr>
<td><input type="checkbox" name="qx" onclick="quanxuan(this)"/>代號(hào)</td>
<td>名稱(chēng)</td>
</tr>
<?php
require"DBDA.class1.php";
$db = new DBDA();
$sql = "select * from nation";
$arr = $db->query($sql);
foreach($arr as $v)
{
echo "<tr>
<td><input type='checkbox' name='ck[]' class='ck' value='{$v[0]}'/>{$v[0]}</td>
<td>{$v[1]}</td>
</tr>";
}
?>
</table>
<input type="submit" value="批量刪除" />
</form>
</body>
<script type="text/javascript">
function quanxuan(qx)
{
var ck=document.getElementsByClassName("ck");
if(qx.checked)
{
for(var i=0;i<ck.length;i++)
{
ck[i].setAttribute("checked","checked");
}
}
else
{
for(var i=0;i<ck.length;i++)
{
ck[i].removeAttribute("checked");
}
}
}
</script>
</html>
引用的封裝類(lèi) DBDA.class1.php
<?php
class DBDA
{
public $host = "localhost";
public $uid = "root";
public $pwd = "123";
public $dbname = "test_123";
//執(zhí)行SQL語(yǔ)句返回相應(yīng)的結(jié)果
//$sql 要執(zhí)行的SQL語(yǔ)句
//$type 代表SQL語(yǔ)句的類(lèi)型,0代表增刪改,1代表查詢(xún)
function query($sql,$type=1)
{
$db = new MySQLi($this->host,$this->uid,$this->pwd,$this->dbname);
$result = $db->query($sql);
if($type)
{
//如果是查詢(xún),顯示數(shù)據(jù)
return $result->fetch_all();
}
else
{
//如果是增刪改,返回true或者false
return $result;
}
}
}
2.刪除處理界面 sanchu.php
<?php
$arr = $_POST["ck"];
require"DBDA.class.php";
$db = new DBDA();
//delete from nation where code in('n001','n002','n003')
$str = implode("','",$arr);
$sql = "delete from nation where code in('{$str}')";
/*echo $sql;*/
if($db->query($sql,0))
{
header("location:piliangcaozuo.php");
}
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- php批量刪除數(shù)據(jù)
- thinkphp框架實(shí)現(xiàn)刪除和批量刪除
- PHP 批量刪除 sql語(yǔ)句
- 基于ThinkPHP實(shí)現(xiàn)批量刪除
- php批量刪除操作代碼分享
- 使用php批量刪除數(shù)據(jù)庫(kù)下所有前綴為prefix_的表
- PHP實(shí)現(xiàn)批量刪除(封裝)
- php批量添加數(shù)據(jù)與批量更新數(shù)據(jù)的實(shí)現(xiàn)方法
- PHP執(zhí)行批量mysql語(yǔ)句的解決方法
- Thinkphp批量更新數(shù)據(jù)的方法匯總
- PHP+JS實(shí)現(xiàn)批量刪除數(shù)據(jù)功能示例
相關(guān)文章
PHP 生成N個(gè)不重復(fù)的隨機(jī)數(shù)
本文給大家展示的是一個(gè)實(shí)例,實(shí)用php實(shí)現(xiàn)了生產(chǎn)N個(gè)不同的隨機(jī)數(shù),實(shí)現(xiàn)思路和方法都介紹給了大家,小伙伴們參考下吧。2015-01-01
Windows下部署Apache+PHP+MySQL運(yùn)行環(huán)境實(shí)戰(zhàn)
本來(lái)嘛,部署PHP沒(méi)什么復(fù)雜,找各種版本著實(shí)頭疼了一下。2012-08-08
PHP 中使用ajax時(shí)一些常見(jiàn)錯(cuò)誤總結(jié)整理
利用php_imagick實(shí)現(xiàn)復(fù)古效果的方法
PHP正則表達(dá)式過(guò)濾html標(biāo)簽屬性(DEMO)
Thinkphp極驗(yàn)滑動(dòng)驗(yàn)證碼實(shí)現(xiàn)步驟解析
PHP通過(guò)加鎖實(shí)現(xiàn)并發(fā)情況下?lián)尨a功能

