PHP實(shí)現(xiàn)批量刪除(封裝)
更新時(shí)間:2017年04月28日 14:54:14 作者:下頁、再停留
本篇文章主要介紹了PHP實(shí)現(xiàn)批量刪除(封裝)的相關(guān)知識(shí)。具有很好的參考價(jià)值。下面跟著小編一起來看下吧
前臺(tái)
<!DOCTYPE html>
<html>
<head>
<title>批量刪除</title>
</head>
<body>
<script type="text/javascript">
//復(fù)選框
function checkall(all)
{
var ck = document.getElementsByClassName("ck");
if(all.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>
<form action="test.php" method="post">
<table border="1">
<tr><th><input type="checkbox" name="all" onclick="checkall(this)"/>id</th><th>名字</th></tr>
<!-- 此處調(diào)用顯示列表函數(shù) -->
<?php show() ?>
<tr><td colspan="3"><input type="submit" value="批量刪除"></td></tr>
</table>
</form>
</body>
<?php
//顯示列表
function show()
{
//連接數(shù)據(jù)庫
@mysql_connect('localhost','root','');
mysql_select_db('test');
mysql_query('set names utf8');
$sql = "select id,name from test";
$res = mysql_query($sql);
//循環(huán)取出數(shù)據(jù)
while($row = mysql_fetch_row($res))
{
echo "<tr>
<td>
<input type='checkbox' value='{$row[0]}' name='item[]' class='ck' />
{$row[0]}
</td>
<td>{$row[1]}</td>
</tr>";
}
}
?>
</html>
后臺(tái)
<?php
//接收post傳來的數(shù)組
$arr = $_POST["item"];
/**
* 批量刪除
* 思路:把前臺(tái)批量選擇的數(shù)據(jù)放在數(shù)組里,刪除該數(shù)組即可
* @param $arr <array()>
* @return $res 成功or失敗
*/
function batch_del($arr)
{
@mysql_connect('localhost','root','');
mysql_select_db('test');
mysql_query('set names utf8');
//把數(shù)組元素組合為字符串:
$str = implode("','",$arr);
//in 表示多個(gè)
$sql = "delete from test where id in('{$str}')";
$res = mysql_query($sql);
if (!$res){
echo "刪除失敗";
}else {
if (mysql_affected_rows()>0){
echo "刪除成功";
}else {
echo "沒有行受到影響";
}
}
}
//調(diào)用批量刪除函數(shù)
batch_del($arr);
以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時(shí)也希望多多支持腳本之家!
您可能感興趣的文章:
- php批量刪除數(shù)據(jù)
- thinkphp框架實(shí)現(xiàn)刪除和批量刪除
- PHP 批量刪除 sql語句
- 基于ThinkPHP實(shí)現(xiàn)批量刪除
- php批量刪除操作代碼分享
- 使用php批量刪除數(shù)據(jù)庫下所有前綴為prefix_的表
- php批量刪除操作(數(shù)據(jù)訪問)
- php批量添加數(shù)據(jù)與批量更新數(shù)據(jù)的實(shí)現(xiàn)方法
- PHP執(zhí)行批量mysql語句的解決方法
- Thinkphp批量更新數(shù)據(jù)的方法匯總
- PHP+JS實(shí)現(xiàn)批量刪除數(shù)據(jù)功能示例
相關(guān)文章
php實(shí)現(xiàn)簡單路由實(shí)現(xiàn)偽靜態(tài)
這篇文章主要為大家詳細(xì)介紹了php如何實(shí)現(xiàn)簡單路由實(shí)現(xiàn)偽靜態(tài),文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-04-04
PHP實(shí)現(xiàn)對(duì)png圖像進(jìn)行縮放的方法(支持透明背景)
這篇文章主要介紹了PHP實(shí)現(xiàn)對(duì)png圖像進(jìn)行縮放的方法(支持透明背景),可實(shí)現(xiàn)php針對(duì)png圖像的縮放功能,且支持透明背景,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-07-07
將word轉(zhuǎn)化為swf 如同百度文庫般閱讀實(shí)現(xiàn)思路及代碼
一般流程想將word轉(zhuǎn)化為pdf格式,再將pdf格式轉(zhuǎn)化為swf格式。在網(wǎng)頁上顯示其實(shí)都是swf格式內(nèi)容,具體實(shí)現(xiàn)如下,有此需求的朋友可以參考下,希望對(duì)大家有所幫助2013-08-08
PHP 正則判斷中文UTF-8或GBK的思路及具體實(shí)現(xiàn)
UTF-8匹配: 在javascript中,要判斷字符串是中文是很簡單的,下面有個(gè)不錯(cuò)的判斷示例,需要的朋友可以參考下2013-11-11
php使用preg_match()函數(shù)驗(yàn)證ip地址的方法
這篇文章主要介紹了php使用preg_match()函數(shù)驗(yàn)證ip地址的方法,涉及php針對(duì)數(shù)字及字符串的正則匹配操作相關(guān)技巧,需要的朋友可以參考下2017-01-01

