php配合jquery实现增删操作具体实例
2013-12-12 17:48
701 查看
后台使用php,前台引用jquery,实现增删操作,代码如下:
游戏蛮牛 代码如下:
<script type="text/javascript" src="jquery-1.10.2.min.js"></script>
<?php
header("Content-type: text/html; charset=utf-8");
//mysql_connect 建立连接,mysql_close($link)关闭非永久连接,mysql_pconnect 建立永久连接
//mysql_error返回mysql函数错误信息,mysql_errno返回mysql函数错误号码
//mysql_set_charset 设置用户端字符集,mysql_select_db 选择连接数据库
//mysql_query 执行查询,mysql_num_rows返回查询记录条数
//mysql_affected_rows返回受影响的记录条数,mysql_free_result 释放结果集内存
//mysql_fetch_row 返回列举阵列记录,mysql_fetch_assoc 返回关联阵列记录
//mysql_fetch_array 返回关联阵列或数字阵列记录,mysql_fetch_object 返回物件形式记录
//mysql_fetch_result 取得结果集资料
//%s 字符串,%c 一个ASCII字符,%d 一个整数,%u 一个符号数,%x 一个十六进制数
mysql_query("set charaset set utf-8");
$message=@$_POST["message"];
$shanchu=@$_POST["shanchu"];
$top_title="PHP基础练习";
$con=mysql_connect("localhost","root","");
//连接数据库
mysql_set_charset('utf-8',$con);
mysql_select_db("dbl",$con);
//定义数据库命令查询
$sql="select `message` ,`time`,`id` from message order by id desc limit 0,30";
//执行数据库查询
$rs=mysql_query($sql,$con);
$time=date('Y-m-d h:i:s',time());
//获取条数
$num_rows=mysql_num_rows($rs);//mysql_num_rows返回查询记录条数
if (isset($_POST["submits"])) {
if(!$_POST["message"]==null){
$queryinsert=sprintf("insert into message (message,time) values('%s','%s')",
$_POST['message'],$time);
mysql_query($queryinsert,$con);
}
if($_POST["message"]==null){
echo "";
}
header("Location:http://localhost/table.php");
}
if(isset($_GET["ClearTd"]) && intval($_GET['ClearTd'])){
$querydelete="delete from message where id=".$_GET['ClearTd'];
mysql_query($querydelete,$con);
header("Location:http://localhost/table.php");
}
?>
unity3d http://www.unitymanual.com/
<form method="post" action="table.php">
<textarea name="message" id="message"></textarea>
<input type="submit" name="submits">
</form>
<ul>
<?php while($row=mysql_fetch_array($rs,MYSQL_ASSOC))
{
?>
<li>
<?php foreach($row as $tiao){
echo $tiao;
}?>
<a name="ClearTd" href="?ClearTd=<?php echo $row['id'];?>">删除</a>
</li>
<?php } ?>
</ul>
游戏蛮牛 代码如下:
<script type="text/javascript" src="jquery-1.10.2.min.js"></script>
<?php
header("Content-type: text/html; charset=utf-8");
//mysql_connect 建立连接,mysql_close($link)关闭非永久连接,mysql_pconnect 建立永久连接
//mysql_error返回mysql函数错误信息,mysql_errno返回mysql函数错误号码
//mysql_set_charset 设置用户端字符集,mysql_select_db 选择连接数据库
//mysql_query 执行查询,mysql_num_rows返回查询记录条数
//mysql_affected_rows返回受影响的记录条数,mysql_free_result 释放结果集内存
//mysql_fetch_row 返回列举阵列记录,mysql_fetch_assoc 返回关联阵列记录
//mysql_fetch_array 返回关联阵列或数字阵列记录,mysql_fetch_object 返回物件形式记录
//mysql_fetch_result 取得结果集资料
//%s 字符串,%c 一个ASCII字符,%d 一个整数,%u 一个符号数,%x 一个十六进制数
mysql_query("set charaset set utf-8");
$message=@$_POST["message"];
$shanchu=@$_POST["shanchu"];
$top_title="PHP基础练习";
$con=mysql_connect("localhost","root","");
//连接数据库
mysql_set_charset('utf-8',$con);
mysql_select_db("dbl",$con);
//定义数据库命令查询
$sql="select `message` ,`time`,`id` from message order by id desc limit 0,30";
//执行数据库查询
$rs=mysql_query($sql,$con);
$time=date('Y-m-d h:i:s',time());
//获取条数
$num_rows=mysql_num_rows($rs);//mysql_num_rows返回查询记录条数
if (isset($_POST["submits"])) {
if(!$_POST["message"]==null){
$queryinsert=sprintf("insert into message (message,time) values('%s','%s')",
$_POST['message'],$time);
mysql_query($queryinsert,$con);
}
if($_POST["message"]==null){
echo "";
}
header("Location:http://localhost/table.php");
}
if(isset($_GET["ClearTd"]) && intval($_GET['ClearTd'])){
$querydelete="delete from message where id=".$_GET['ClearTd'];
mysql_query($querydelete,$con);
header("Location:http://localhost/table.php");
}
?>
unity3d http://www.unitymanual.com/
<form method="post" action="table.php">
<textarea name="message" id="message"></textarea>
<input type="submit" name="submits">
</form>
<ul>
<?php while($row=mysql_fetch_array($rs,MYSQL_ASSOC))
{
?>
<li>
<?php foreach($row as $tiao){
echo $tiao;
}?>
<a name="ClearTd" href="?ClearTd=<?php echo $row['id'];?>">删除</a>
</li>
<?php } ?>
</ul>
相关文章推荐
- php配合jquery实现增删操作具体实例
- php配合jquery实现增删操作具体实例
- php配合jquery实现增删操作具体实例
- php配合jquery实现增删操作
- jquery-easyui实现页面布局和增删改查操作(SSH2框架支持)转载
- PHP+MySQL实现对一段时间内每天数据统计优化操作实例
- hibernate通过session实现增删改查操作实例解析
- 用jquery代码实现表格行列的增删操作(每行编号随之修改)
- jQuery结合PHP+MySQL实现二级联动下拉列表[实例]
- Jquery实现遮罩层的简单实例(就是弹出DIV周围都灰色不能操作)
- PHP实现的连贯操作、链式操作实例
- PHP基于PDO实现的SQLite操作类【包含增删改查及事务等操作】
- DOM操作和jQuery实现选项移动操作的简单实例
- 利用PHP访问MySql数据库的逻辑操作以及增删改查的实例讲解
- PHP jQuery表单,带验证具体实现方法
- PHP+jquery+ajax实现即时聊天功能实例
- php使用PDO事务配合表格读取大量数据插入操作实现方法
- php中cookie实现二级域名可访问操作实例
- PHP结合jQuery插件ajaxFileUpload实现异步上传文件实例