0

我有 2 张桌子criminaloffender. 我创建了另一个名为subject执行查询的表,它工作得非常好:代码如下:

显示主题.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>

显示主题脚本.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现在,一旦会话关闭,我必须删除表的字段值。任何人都可以帮助我.. ??

4

1 回答 1

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

于 2013-06-29T06:19:50.163 回答