Home >Backend Development >PHP Tutorial >php 删除记录实现代码_PHP

php 删除记录实现代码_PHP

WBOY
WBOYOriginal
2016-06-01 12:23:361099browse
复制代码 代码如下:
@mysql_connect("localhost", "root","1981427") //选择数据库之前需要先连接数据库服务器
or die("数据库服务器连接失败");
@mysql_select_db("test") //选择数据库mydb
or die("数据库不存在或不可用");
$query = @mysql_query("select * from tablename1") //执行SQL语句
or die("SQL语句执行失败");
echo "
";
echo "";
//通过循环的方式输出从第0行到最大的一行的所有记录
for($i=0; $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 "
";
echo "";
echo "";
echo "";
echo "";
echo "";
}
echo "";
echo "";
echo "
$id$username$password
";
echo "
";
?>


复制代码 代码如下:
@mysql_connect("localhost", "root","1981427") //选择数据库之前需要先连接数据库服务器
or die("数据库服务器连接失败");
@mysql_select_db("test") //选择数据库mydb
or die("数据库不存在或不可用");
foreach($_POST['chk'] AS $check)
{
$query = mysql_query("delete from tablename1 where id = $check");
if($query)
echo "删除成功";
else
echo "删除失败";
}
mysql_close();
?>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn