用php写网页对mysql进行删除,查询

如题所述

第1个回答  2012-05-07
我刚刚写了一堆代码,正好是你想要的,什么都写完整了,有写入记录,修改记录,删除记录,还有分页显示,不过没写注释 希望对你有帮助
<?php
<?php
$link = mysql_connect("localhost","root");
mysql_select_db("student",$link);
mysql_query("SET NAMES GB2312");
?>
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>PHP结合MYSQL数据库</title>
</head>

<body>
<?
$page = $_GET["page"];
if($page==""){
$page = 1;
}elseif($page<1){
$page = 1;
}else{
$page = $_GET["page"];
}
$sql = "select * from news";
$rows = mysql_query($sql);
$num = mysql_num_rows($rows);
$time = ($page-1)*3;
$recordcount = ceil($num/3);
$sql = "select * from news order by id limit ".$time.",3";
$result = mysql_query($sql);
while($rs = mysql_fetch_array($result))
{
echo $rs["id"]."  ".$rs["title"]."  ".$rs["content"]."  ".$rs["data"]."  <a href='content.php?nid=".$rs["id"]."'>删除</a>  <a href='content.php?zid=".$rs["id"]."'>编辑</a><br /><br />";
}
echo "<br />";
echo "总共有 ".$num." 条数据  ";
echo "共有 ".$recordcount." 页  ";
echo "当前是第 ".$page." 页  ";
echo "每页显示 5 条数据<br /><br />";
if($page == 1){
echo "首页  上一页  ";
}else{
echo "<a href='content.php?page=1'>首页</a>  <a href='content.php?page=".($page-1)."'>上一页</a>  ";
}
if($page == $recordcount){
echo "下一页  尾页  ";
}else{
echo "<a href='content.php?page=".($page+1)."'>下一页</a>  <a href='content.php?page=".$recordcount."'>尾页</a>  ";
}
$zid = $_GET["zid"];
if($zid==""){
?>
<form action="content.php" method="post" name="form1">
标题  <input type="text" name="title"><br /><br />
内容  <textarea name="content" cols="60" rows="10"></textarea><br /><br />
时间  <input type="text" name="data" value="<?=date("Y-m-d")?>"><br /><br />
<input type="submit" name="submit" value="写入" style="margin-left:45px;">
</form>
<? }else{
$sql = "select * from news where id=".$zid." order by id";
$rows = mysql_query($sql);
$rs = mysql_fetch_array($rows);
?>
<form action="content.php?xid=<?=$rs["id"]?>" method="post" name="form1">
标题  <input type="text" name="title1" value="<?=$rs["title"]?>"><br /><br />
内容  <textarea name="content1" cols="60" rows="10"><?=$rs["content"]?></textarea><br /><br />
时间  <input type="text" name="data1" value="<?=$rs["data"]?>"><br /><br />
<input type="submit" name="submit1" value="修改" style="margin-left:45px;">
</form>
<? }?>
</body>
</html>
<?php
$title = $_POST["title"];
$content = $_POST["content"];
$data = $_POST["data"];
if($title<>""){
$sql="insert into news(title,content,data) values('".$title."','".$content."','".$data."')";
mysql_query($sql);
echo "<meta http-equiv='refresh' content='0; url=content.php'>";
}
$nid = $_GET["nid"];
if($nid<>""){
$sql="delete from news where id = ".$nid."";
mysql_query($sql);
echo "<meta http-equiv='refresh' content='0; url=content.php'>";
}
$title1 = $_POST["title1"];
$content1 = $_POST["content1"];
$data1 = $_POST["data1"];
$xid = $_GET["xid"];
if($title1<>""){
$sql = "update news set title = '".$title1."',content = '".$content1."',data = '".$data1."' where id = ".$xid."";
mysql_query($sql);
echo "<meta http-equiv='refresh' content='0; url=content.php'>";
}
?>
第2个回答  2012-05-08
select
delete
自己看手册都有这些的
第3个回答  2012-05-07
那就写吧!

php封装一个类能实现mysql数据库的增删改查(php增删改查mysql实例)
this-<conn=mysql_connect($this-<host,$this-<username,$this-<password);if(!$this-<conn){ die("连接失败".mysql_error());} mysql_select_db($this-<dbname,$this-<conn);} \/\/执行查询语句 public function execute_dql($sql){ res=mysql_query($sql,$this-<conn);return res;} \/...

用php写网页对mysql进行删除,查询
sql = "select * from news order by id limit ".$time.",3";result = mysql_query($sql);while($rs = mysql_fetch_array($result)){ echo $rs["id"]."".$rs["title"]."".$rs["content"]."".$rs["data"]."删除编辑";} echo "";echo "总共有 ".$num." 条数据";echo ...

查找数据库(mysqli)里面的数据并且删除或者添加,php代码怎么写求大神帮...
php$conn=new MySQLi("db_host","db_username","db_password");$conn->select_db("db_name");\/\/查询$sql="select * from table_name";\/\/添加$sql='insert into table_name(column1,column2) values("value1","value2")';\/\/修改$sql='update table_name set column1="value1" , c...

PHP删除数据库记录
1、首先在视图页面找到要删除的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 "";echo "部门名称员工姓名PC名称";while($row =...

PHP操作MySQL,删除一行数据库,怎么写?
删除数据库中的数据 delete from 语句用于从数据库表中删除记录。语法 delete from table_name where column_name = some_value 注释:sql 对大小写不敏感。delete from 与 delete from 等效。为了让 php 执行上面的语句,我们必须使用 mysql_query( 函数。该函数用于向 sql 连接发送查询和命令 ...

php 中 怎么实现点击按钮 然后从MYSQL中删除对应行的数据
.post('这是你执行删除动作的php文件,如:del_post.php',{id:$id},function(result){ alert(result); })});});}) 至于如何执行删除操作,可以参考一些MYSQL数据库的知识。大致语句为:id = $_POST["id"] ? $_POST["id"] : 0;sql = "Delete from [数据表] where id = ".$id;...

php,点击超链接文本,转向实现删除\/修改mysql数据
delete.php(不推荐)要么 都写在一个页面,然后switch case 判断操作 接受id 然后执行 删除 这样比较推荐 delete.php页面里 连好数据库 switch($act=$_GET['act']){ case 'del': ...;break;case...}

PHP怎么写可以清空MYSQL数据库中一个表里面的值!
不带where参数的delete语句可以删除mysql表中所有内容,使用truncate table也可以清空mysql表中所有内容。效率上truncate比delete快,但truncate删除后不记录mysql日志,不可以恢复数据。delete的效果有点像将mysql表中所有记录一条一条删除到删完,而truncate相当于保留mysql表的结构,重新创建了这个表,所有的状态都相当于新表...

怎样用php+mysql 做一个查询的网页
<?php \/\/连接数据库 con=mysqli_connect("localhost","root","123456","mydb");\/\/SQL语句 sql="select * from mytab;";\/\/执行SQL语句,结果保存到$arr obj=mysqli_query($con,$sql);arr=mysqli_num_rows($result);?> 实现最简单的php网页+mysql查询功能 <?php echo "";print...

php数据库添加、删除、修改数据(mysql)
删除数据 <?php query = "DELETE FROM grade WHERE id=6";mysql_query($query) or die( '删除错误:' .mysql_error());?> 显示数据 <?php query = "SELECT id,name,email,point FROM grade";result = @mysql_query($query) or die( '查询语句出错:' .mysql_error());while (!! $...

相似回答
大家正在搜