窗口关闭后如何删除表的字段值?

时间:2013-06-29 06:13:28

标签: php javascript

我有2个表criminaloffender。我已经创建了另一个名为subject的表,其中执行了一个查询,它的工作效果令人惊讶:这就是代码:

showsubject.php

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>Google Maps AJAX + mySQL/PHP Example</title>
    <script src="http://maps.google.com/maps/api/js?sensor=false"
            type="text/javascript"></script>
    <script type="text/javascript">


    var customIcons = {
      criminal: {
        icon: 'http://labs.google.com/ridefinder/images/mm_20_blue.png',
        shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
      },
      offender: {
        icon: 'http://labs.google.com/ridefinder/images/mm_20_red.png',
        shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
      }
    };



    function load() {
      var map = new google.maps.Map(document.getElementById("map"), {
        center: new google.maps.LatLng(-20.1666591, 57.503457),
        zoom: 13,
        mapTypeId: 'roadmap'
      });
      var infoWindow = new google.maps.InfoWindow;

      downloadUrl("showsubject-script1.php", function(data) {
        var xml = data.responseXML;
        var markers = xml.documentElement.getElementsByTagName("marker");

        for (var i = 0; i < markers.length; i++) {
          var subid      = markers[i].getAttribute("subid");
          var subaddress = markers[i].getAttribute("subaddress");
          var subtype    = markers[i].getAttribute("subtype");
          var point      = new google.maps.LatLng(
              parseFloat(markers[i].getAttribute("sublat")),
              parseFloat(markers[i].getAttribute("sublng")));
          var html       = "<b>" + subid + "</b> <br/>" + subaddress;
          var icon       = customIcons[subtype] || {};
          var marker     = new google.maps.Marker({
            map: map,
            position: point,
            icon: icon.icon,


          });
          bindInfoWindow(marker, map, infoWindow, html);
        }

      });
    }



    function bindInfoWindow(marker, map, infoWindow, html) {
      google.maps.event.addListener(marker, 'click', function() {
        infoWindow.setContent(html);
        infoWindow.open(map, marker);
      });
    }



    function downloadUrl(url, callback) {
      var request = window.ActiveXObject ?
          new ActiveXObject('Microsoft.XMLHTTP') :
          new XMLHttpRequest;

      request.onreadystatechange = function() {
        if (request.readyState == 4) {
          request.onreadystatechange = doNothing;
          callback(request, request.status);
        }
      };

      request.open('GET', url, true);
      request.send(null);
    }

    function doNothing() {}


  </script>
  </head>

  <body onLoad="load()">
    <div id="map" style="width: 900px; height: 1000px"></div>
  </body>
</html>

SHOWSUBJECTSCRIPT.PHP

<?php
require("db.php");

function parseToXML($htmlStr) 
{ 
$xmlStr=str_replace('<','&lt;',$htmlStr);  
$xmlStr=str_replace('>','&gt;',$xmlStr); 
$xmlStr=str_replace('"','&quot;',$xmlStr); 
$xmlStr=str_replace("'",'&#39;',$xmlStr); 
$xmlStr=str_replace("&",'&amp;',$xmlStr); 
return $xmlStr; 
} 

  $query1 = mysql_query ("SELECT id,address,lat,lng 'criminal' FROM criminal");

while ($row1 = mysql_fetch_array($query1) )
{
$insert1= mysql_query("insert into subject (subid,subaddress,sublet,sublng,subtype)
               values( '$row[0]', '$row[1]', '$row[2]', '$row[3]','$row[4]') ");
}

$query2 = mysql_query ("SELECT id,address,lat,lng 'offender' FROM offender");

while ($row2 = mysql_fetch_array($query2) )
{
$insert2= mysql_query("insert into subject (subid,subaddress,sublat,sublng,subtype)
               values( '$row[0]', '$row[1]', '$row[2]', '$row[3]','$row[4]') ");
}

$query3 = mysql_query ("SELECT * FROM subject");

header("Content-type: text/xml");
echo '<markers>';

while ($row3 = @mysql_fetch_assoc($query3)){


  // ADD TO XML DOCUMENT NODE
  echo '<marker ';
  echo 'subid="' .      parseToXML($row3['subid']) . '" ';
  echo 'subaddress="' . parseToXML($row3['subaddress']) . '" ';
  echo 'sublat="' .                $row3['sublat'] . '" ';
  echo 'sublng="' .                $row3['sublng'] . '" ';
  echo 'subtype="' .               $row3['subtype'] . '" ';


  echo '/>';
}

// End XML file
echo '</markers>';



?>

现在,我必须在会话结束后删除表offender的字段值。任何人都可以帮助我...... ??

1 个答案:

答案 0 :(得分:1)

执行此操作的最佳方法是使用cron。编写将执行清理的php脚本并设置cron,每隔x分钟运行一次,然后为您运行它。

http://net.tutsplus.com/tutorials/php/managing-cron-jobs-with-php-2/

另一个选项可能是使用ignore_user_abort(),具体取决于你想要从罪犯表中删除数据的确切程度

http://php.net/manual/en/function.ignore-user-abort.php