怎么在php中使用jquery实现增删操作

发布时间:2021-01-25 16:33:31 作者:Leah
来源:亿速云 阅读:185

本篇文章给大家分享的是有关怎么在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");   
}
?>

<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实现增删操作,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注亿速云行业资讯频道。

推荐阅读:
  1. jquery实现table增删改
  2. 怎么在jquery中操作select

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

php jquery

上一篇:怎么在PHP中通过table标签输出EXCEL

下一篇:利用PHP怎么对缓冲区进行控制

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》