zoukankan      html  css  js  c++  java
  • php配合jquery实现增删操作

    后台使用php,前台引用jquery,实现增删操作,代码如下:

     1 <script type="text/javascript" src="http://keleyi.com/keleyi/pmedia/jquery/jquery-1.10.2.min.js"></script> 
     2 <?php 
     3 header("Content-type: text/html; charset=utf-8"); 
     4 //mysql_connect 建立连接,mysql_close($link)关闭非永久连接,mysql_pconnect 建立永久连接 
     5 //mysql_error返回mysql函数错误信息,mysql_errno返回mysql函数错误号码 
     6 //mysql_set_charset 设置用户端字符集,mysql_select_db 选择连接数据库 
     7 //mysql_query 执行查询,mysql_num_rows返回查询记录条数 
     8 //mysql_affected_rows返回受影响的记录条数,mysql_free_result 释放结果集内存 
     9 //mysql_fetch_row 返回列举阵列记录,mysql_fetch_assoc 返回关联阵列记录 
    10 //mysql_fetch_array 返回关联阵列或数字阵列记录,mysql_fetch_object 返回物件形式记录 
    11 //mysql_fetch_result 取得结果集资料 
    12 //%s 字符串,%c 一个ASCII字符,%d 一个整数,%u 一个符号数,%x 一个十六进制数 
    13 mysql_query("set charaset set utf-8"); 
    14 $message=@$_POST["message"]; 
    15 $shanchu=@$_POST["shanchu"]; 
    16 $top_title="PHP基础练习"; 
    17 $con=mysql_connect("localhost","root",""); 
    18 //连接数据库  
    19 mysql_set_charset('utf-8',$con); 
    20 mysql_select_db("dbl",$con); 
    21 //定义数据库命令查询 
    22 $sql="select `message` ,`time`,`id` from message order by id desc limit 0,30"; 
    23 //执行数据库查询  http://www.cnblogs.com/roucheng/
    24 $rs=mysql_query($sql,$con); 
    25 $time=date('Y-m-d h:i:s',time()); 
    26 //获取条数 
    27 
    28 $num_rows=mysql_num_rows($rs);//mysql_num_rows返回查询记录条数 
    29 if (isset($_POST["submits"])) { 
    30 if(!$_POST["message"]==null){ 
    31 $queryinsert=sprintf("insert into message (message,time) values('%s','%s')", 
    32 $_POST['message'],$time); 
    33 mysql_query($queryinsert,$con); 
    34 } 
    35     if($_POST["message"]==null){ 
    36 echo ""; 
    37 } 
    38 header("Location:http://localhost/table.php"); 
    39 } 
    40 
    41 if(isset($_GET["ClearTd"]) && intval($_GET['ClearTd'])){ 
    42 $querydelete="delete from message where id=".$_GET['ClearTd']; 
    43     mysql_query($querydelete,$con); 
    44 header("Location:http://localhost/table.php");    
    45 } 
    46 ?> 
    47 
    48 <form method="post" action="table.php"> 
    49 <textarea  name="message" id="message"></textarea> 
    50 <input type="submit" name="submits"> 
    51 </form> 
    52 
    53 <ul> 
    54 <?php while($row=mysql_fetch_array($rs,MYSQL_ASSOC)) 
    55 { 
    56 ?> 
    57 <li> 
    58 <?php foreach($row as $tiao){ 
    59 echo $tiao; 
    60 }?> 
    61     <a name="ClearTd" href="?ClearTd=<?php echo $row['id'];?>">删除</a> 
    62 </li>       
    63 <?php } ?> 
    64 </ul> 
  • 相关阅读:
    性能测试相关名词
    Java中的并发工具类:CountDownLatch、CyclicBarrier和Semaphore
    spring与mybatis五种整合方法
    Powerdesigner使用技巧
    基于Redis的Spring cache 缓存介绍
    AspectJ AOP介绍
    Spring AOP的实现原理
    -webkit-tap-highlight-color
    Zero Clipboard js+swf实现的复制功能使用方法
    CSS3 RGBA 属性高级用法
  • 原文地址:https://www.cnblogs.com/roucheng/p/3467271.html
Copyright © 2011-2022 走看看