php 刪除記錄實現(xiàn)代碼
更新時間:2009年03月12日 23:20:07 作者:
這里讓大家知道php下刪除記錄的實現(xiàn)方法
復(fù)制代碼 代碼如下:
<?php
@mysql_connect("localhost", "root","1981427") //選擇數(shù)據(jù)庫之前需要先連接數(shù)據(jù)庫服務(wù)器
or die("數(shù)據(jù)庫服務(wù)器連接失敗");
@mysql_select_db("test") //選擇數(shù)據(jù)庫mydb
or die("數(shù)據(jù)庫不存在或不可用");
$query = @mysql_query("select * from tablename1") //執(zhí)行SQL語句
or die("SQL語句執(zhí)行失敗");
echo "<form method='post' name='form1' action='delete_do.php'>";
echo "<table border=1>";
//通過循環(huán)的方式輸出從第0行到最大的一行的所有記錄
for($i=0; $i<mysql_numrows($query); $i++)
{
$id = mysql_result($query, $i, 'id'); //輸出第$i行的serial_no列
$username = mysql_result($query, $i, 'username'); //輸出第$i行的name列
$password = mysql_result($query, $i, 'password'); //輸出第$i行的salary列
echo "<tr>";
echo "<td><input type='checkbox' name='chk[]' value='$id'></td>";
echo "<td>$id</td>";
echo "<td>$username</td>";
echo "<td>$password</td>";
echo "</tr>";
}
echo "<tr>";
echo "<td colspan=4 nowrap><input name='Submit' type='submit' value='提交'>";
echo "<input type='reset' name='Reset' value='重設(shè)'></td>";
echo "</tr></table></form>";
?>
復(fù)制代碼 代碼如下:
<?php
@mysql_connect("localhost", "root","1981427") //選擇數(shù)據(jù)庫之前需要先連接數(shù)據(jù)庫服務(wù)器
or die("數(shù)據(jù)庫服務(wù)器連接失敗");
@mysql_select_db("test") //選擇數(shù)據(jù)庫mydb
or die("數(shù)據(jù)庫不存在或不可用");
foreach($_POST['chk'] AS $check)
{
$query = mysql_query("delete from tablename1 where id = $check");
if($query)
echo "刪除成功";
else
echo "刪除失敗";
}
mysql_close();
?>
相關(guān)文章
php實現(xiàn)執(zhí)行某一操作時彈出確認、取消對話框
當執(zhí)行某一操作比如確認或者取消時如何彈出對話框,針對這個需求,下面使用php來實現(xiàn)下,感興趣的朋友不要錯過2013-12-12php將數(shù)據(jù)庫中所有內(nèi)容生成靜態(tài)html文檔的代碼
比較簡單了,而且我的代碼優(yōu)化也很是問題 比較繁瑣。下面就直接上代碼了2010-04-04php簡單開啟gzip壓縮方法(zlib.output_compression)
網(wǎng)上的教程基本是你抄我來我抄他,不外乎加頭加尾或者自構(gòu)函數(shù)兩種寫法。實際上每個php頁面都要去加代碼——當然也可以include引用,不過總顯得略微麻煩2013-04-04php獲取一定范圍內(nèi)取N個不重復(fù)的隨機數(shù)
這篇文章主要介紹了php獲取一定范圍內(nèi)取N個不重復(fù)的隨機數(shù)的方法,通過range函數(shù)創(chuàng)建指定范圍內(nèi)數(shù)組及shuffle進行數(shù)組隨機排序,并使用array_slice抽取數(shù)組實現(xiàn)該功能,非常簡單實用,需要的朋友可以參考下2016-05-05Mysql數(shù)據(jù)庫操作類( 1127版,提供源碼下載 )
Mysql數(shù)據(jù)庫操作類,學(xué)習(xí)php的朋友可以參考下。2010-12-12