您当前的位置: 首页 > 网站编程 > PHP教程 > php配合jquery实现增删操作具体实例

php配合jquery实现增删操作具体实例

作者:不详 来源:网络 发布时间: 2014-08-13 18:41 点击:
这篇文章主要介绍了php配合jquery实现增删操作具体实例,有需要的朋友可以参考一下 后台使用php,前台引用jquery,实现增删操作,代码如下: 代码如下: script type=text/javascript src=jquery-1.10.2.min.js/script ?php header(Content-type: text/html; charset=ut

php配合jquery实现增删操作具体实例

  这篇文章主要介绍了php配合jquery实现增删操作具体实例,有需要的朋友可以参考一下

  后台使用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实现增删操作具体实例"由远航站长收集整理而来,仅供大家学习与参考使用。更多网站制作教程尽在远航站长站。
顶一下
(0)
0%
踩一下
(0)
0%
[点击 次] [返回上一页] [打印]
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 密码: 验证码:
关于本站 - 联系我们 - 网站声明 - 友情连接- 网站地图 - 站点地图 - 返回顶部
Copyright © 2007-2013 www.yhzhan.com(远航站长). All Rights Reserved .
远航站长:为中小站长提供最佳的学习与交流平台,提供网页制作与网站编程等各类网站制作教程.
官方QQ:445490277 网站群:26680406 网站备案号:豫ICP备07500620号-4