一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - PHP教程 - Ajax+PHP實現的刪除數據功能示例

Ajax+PHP實現的刪除數據功能示例

2019-06-17 10:35chengqiuming PHP教程

這篇文章主要介紹了Ajax+PHP實現的刪除數據功能,涉及php結合ajax動態交互操作數據庫實現數據查詢與刪除相關操作技巧,需要的朋友可以參考下

本文實例講述了Ajax+PHP實現的刪除數據功能。分享給大家供大家參考,具體如下:

一 代碼

conn.php:

<?php
  $conn = mysql_connect("localhost", "root", " ") or die("連接數據庫服務器失敗!".mysql_error()); //連接MySQL服務器
  mysql_select_db("db_database27",$conn); //選擇數據庫db_database27
  mysql_query("set names utf8"); //設置數據庫編碼格式utf8
?>

del.php:

<?php
  include_once("conn/conn.php");//包含數據庫連接文件
    $id=$_GET['id'];//把傳過來的參數值賦給變量$i
    $sql=mysql_query("delete from tb_demo02 where id=".$id);//根據參數值執行相應的刪除操作
    if($sql){//如果操作的返回值為true
     $reback=1;//把變量$reback的值設為1
    }else{
     $reback=0;//否則變量$reback的值設為0
    }
    echo $reback;//輸出變量$reback的值
?>

index.js:

function del(id){
    var xml;
    if(window.ActiveXObject){//如果是瀏覽器支持ActiveXObjext則創建ActiveXObject對象
     xml=new ActiveXObject('Microsoft.XMLHTTP');
    }else if(window.XMLHttpRequest){//如果瀏覽器支持XMLHttpRequest對象則創建XMLHttpRequest對象
     xml=new XMLHttpRequest();
    }
    xml.open("GET","del.php?id="+id,true);//使用GET方法調用del.php并傳遞參數的值
    xml.onreadystatechange=function(){//當服務器準備就緒執行回調函數
     if(xml.readystate==4 && xml.status==200){//如果服務器已經傳回信息并未發生錯誤
        var msg=xml.responseText;//把服務器傳回的值賦給變量msg
        if(msg==1){//如果服務器傳回的值為1則提示刪除成功
         alert("刪除成功!");
      location.reload();
        }else{//否則提示刪除失敗
         alert("刪除失敗!");
         return false;
        }
   }
    }
    xml.send(null);//不發送任何數據,因為數據已經使用請求URL通過GET方法發送
}

index.php:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>分組統計</title>
<link rel="stylesheet" type="text/css" href="mystyle.css" rel="external nofollow" >
</head>
<body>
<script type="text/javascript" src="index.js"></script>
<center>
<!--banner-->
<table width="798" border="0" cellpadding="0" cellspacing="0">
  <tr>
      <td height="112" background="images/banner.jpg"></td>
  </tr>
</table>
<?php
include_once("conn/conn.php");
?>
<table width="780" border="0" cellpadding="0" cellspacing="0">
<form name="form1" id="form1" method="post" action="deletes.php">
 <tr>
     <td height="20" width="5%" class="top"> </td>
  <td width="5%" class="top">id</td>
  <td width="30%" class="top">書名</td>
  <td width="10%" class="top">價格</td>
  <td width="20%" class="top">出版時間</td>
  <td width="10%" class="top">類別</td>
    <td width="10%" class="top">操作</td>
 </tr>
<?php
    $sqlstr1 = "select * from tb_demo02 order by id";//按id的升序查詢表tb_demo02的數據
    $result = mysql_query($sqlstr1,$conn);//執行查詢語句
    while ($rows = mysql_fetch_array($result)){//循環輸出查詢結果
?>
 <tr>
  <td height="25" align="center" class="m_td">
    <input type=checkbox name="chk[]" id="chk" value=".$rows['id'].">
    </td>
    <td height="25" align="center" class="m_td"><?php echo $rows['id'];?></td>
    <td height="25" align="center" class="m_td"><?php echo $rows['bookname'];?></td>
  <td height="25" align="center" class="m_td"><?php echo $rows['price'];?></td>
    <td height="25" align="center" class="m_td"><?php echo $rows['f_time'];?></td>
    <td height="25" align="center" class="m_td"><?php echo $rows['type'];?></td>
    <td class="m_td"><a href="#" rel="external nofollow" onClick="del(<?php echo $rows['id'];?>)">刪除</a></td>
 </tr>
<?php
    }
?>
<tr>
    <td height="25" colspan="7" class="m_td" align="left">  </td>
</tr>
</form>
</table>
<!--show-->
 <table width="798" border="0" cellpadding="0" cellspacing="0">
  <tr>
   <td height="48" background="images/bottom.jpg"> </td>
  </tr>
</table>
</center>
</body>
</html>

二 運行結果

Ajax+PHP實現的刪除數據功能示例

希望本文所述對大家PHP程序設計有所幫助。

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 天天做天天爱天天综合网 | 香蕉97超级碰碰碰免费公 | 免费看www | 国产91青青成人a在线 | 国模孕妇季玥全部人体写真 | 精品视频一区二区三区 | jazz中国女人护士 | 国产精品久久久久久福利 | 四虎影院com | 色综合久久中文字幕 | 小苹果日本在线观看 | 亚洲免费国产 | 日韩aⅴ在线观看 | 国产精品第3页 | 龟甲情感超市全文阅读 小说 | 国产日韩免费视频 | 免费网站国产 | 天天天做天天天天爱天天想 | 久久国产精品二区99 | 欧美一区二区三区大片 | 湿好紧太硬了我太爽了 | 午夜伦理:伦理片 | 午夜国产精品福利在线观看 | 成年人视频在线 | 欧美1区 | 亚洲成人福利 | www红色一片在线观看版 | 亚洲国产精品综合欧美 | 精品国产线拍大陆久久尤物 | 成年女人免费 | 成人福利免费在线观看 | 日本xxx在线观看免费播放 | 大好硬好深好爽想要视频 | 日韩影院在线观看 | 超级毛片| 国产日本欧美亚洲精品视 | 精品一区二区三区高清免费不卡 | 日本中文字幕在线视频 | 我的漂亮朋友在线观看全集免费 | 青涩体验在线观看未删减 | 99热er|