仅刷新表PHP

时间:2017-10-22 10:28:27

标签: javascript php mysql

因此,此页面正在重新编码数据库中的位置。(此部分正在运行)。 但无论我做什么,我的桌子都不令人耳目一新。我不想刷新桌子本身的整个页面 我只是想在x时间内刷新表格,但是如果我不这样做了,我尝试了很多次,但我无法解决这个问题。

<?php
    $id = (isset($_GET['id'])) ? ((int) $_GET['id']) : 0; // if we got input from user convert to numbers else set to 0
    if($id <= 0) // the number must be greater than 0
        exit();

    require_once("db.php"); // connect to the database
?>
<!DOCTYPE html>
<html>
<head>

    <title>Hello User</title>
    <meta charset="UTF-8">
    <script async defer src="https://maps.googleapis.com/maps/api/js?language=iw&region=IL&key=AIzaSyDyXdL4cZlxo3ldIuvi6_HpZa2jhj7iOU0&callback=initialize"
  type="text/javascript"></script>
    <style>#map { height: 600px; width: 1500px}</style>


<script>

  $(document).ready(function(){
      refreshTable();
    });

    function refreshTable(){
        $('#tablediv').load('googlemaps.php');
        setInterval(refreshTable, 1000);
    }
</script>

</script>
</head>
<body>
    <h1>Tracking Program</h1>
    <div id="map"></div> <!-- map div !-->
    <div id="tablediv">
    <table style="background-color: red;" id="tableid" >
        <thead>
            <tr>
                <th>First Name</th>
                <th>Last Name</th>
                <th>Id</th>
                <th>Phone Number</th>
                <th>Address</th>
            </tr>
        </thead>
        <tbody>

<?php
// get all data from the table and print it
if($result = $db->query("SELECT FirstName, Lastname, Id, Phone,Address FROM details WHERE RowNum ORDER BY RowNum DESC LIMIT 1")) {
    while($row = $result->fetch_assoc()) {
?>
            <tr>
                <td><?=$row['FirstName']; ?></td>
                <td><?=$row['Lastname']; ?></td>
                <td><?=$row['Id']; ?></td>
                <td><?=$row['Phone']; ?></td>
                <td><?=$row['Address']; ?></td>

            </tr>
<?php
    }

    $result->close(); //free the result
}
?>


        </tbody>
    </table>
</div>
</body>

<script type="text/javascript">
var marker, map; // make them global to get access from other functions

function initialize(myLatlng) {
    myLatlng = myLatlng || "<?php include("lastloc.php"); ?>";
    myLatlng = myLatlng.split(",");
    myLatlng = new google.maps.LatLng(myLatlng[0], myLatlng[1]);

    var mapOptions = {
        zoom: 11,
        center: myLatlng
    }
    map = new google.maps.Map(document.getElementById('map'), mapOptions);

    marker = new google.maps.Marker({
        position: myLatlng,
        map: map,
        title: 'מיקום אחרון'
    });
}

// ajax request to load last location
function lastLocation(){
    var xmlhttp;


    xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function(){


        if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
            // method 1
            //initialize(xmlhttp.responseText);

            // method 2
            myLatlng = xmlhttp.responseText.split(",");
            myLatlng = new google.maps.LatLng(myLatlng[0], myLatlng[1]);
            marker.setPosition(myLatlng); // update the position of the marker on the map
            map.setCenter(myLatlng); // update the center of the map
        }
    }
    xmlhttp.open("GET", "lastloc.php?id=<?=$id; ?>", true);
    xmlhttp.send();
}

// timer to refresh the last location we have in the database
setInterval(lastLocation, 5000);


</script>

</html>
<?php
    // close the connection to the datebase
    if($db)
        $db->close();
?>

0 个答案:

没有答案