简体   繁体   English

在PHP中运行SQL查询时自动刷新结果div

[英]auto refresh results div when running SQL Queries in PHP

I have this JS/Ajax code: 我有这个JS / Ajax代码:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready (function () {
    var updater = setTimeout (function () {
        $('div#ContentLeft').load('live_stats1.php', 'update=true')
    $('div#ContentRight').load('live_stats2.php', 'update=true')
    }, 1000);
});
</script>

which refreshes the content divs but they are not refreshing correctly. 这会刷新内容div,但它们不能正确刷新。

My HTML is: 我的HTML是:

<div id="ContentLeft">
<?php include 'live_stats1.php'; ?>
</div>

<div id="ContentLeft">
<?php include 'live_stats2.php'; ?>
</div>

then on live_stats1.php and live_stats2.php i have my queries only 然后在live_stats1.phplive_stats2.php我只有我的查询

the queries take a while to run, so the results disappear until the queries have run again. 查询需要一段时间才能运行,因此结果消失,直到再次运行查询为止。 how can i make it so the results stay in the divs until the new results have loaded? 我如何才能使结果保留在div中,直到加载了新结果?

and also if i check the console in google chrome, the local resources a new jquery.min.js file is added every time it refreshes 并且如果我在谷歌浏览器中检查控制台,则每次刷新时都会在本地资源中添加一个新的jquery.min.js文件

here is a link to what my full PHP code looks like. 这是我完整的PHP代码外观的链接

i want to be able to refresh the result divs only periodically 我希望能够仅定期刷新结果div

Try this 尝试这个

JS : JS:

$(document).ready (function () {



    function updatedivs(responsediv,linkurl)
    {

        $.post(linkurl,function(response){
             $(responsediv).html(response);
        });
    }

    var updater = setTimeout (function () {

          var preventcache =  (new Date).getTime();

          updatedivs($('div#ContentLeft'),'live_stats1.php?update=true&r='+preventcache);
          updatedivs($('div#ContentRight'),'live_stats2.php?update=true&r='+preventcache);

    }, 1000);

});

Html : HTML:

<div id="ContentLeft">
<?php include 'live_stats1.php'; ?>
</div>

<div id="ContentRight">
<?php include 'live_stats2.php'; ?>
</div>

Delete <?php include 'live_stats1.php'; ?> 删除<?php include 'live_stats1.php'; ?> <?php include 'live_stats1.php'; ?> and <?php include 'live_stats2.php'; ?> <?php include 'live_stats1.php'; ?><?php include 'live_stats2.php'; ?> <?php include 'live_stats2.php'; ?> since you will get your stats anyways. <?php include 'live_stats2.php'; ?>因为无论如何您都会获得统计信息。 Also, try to use caching if you have heavy select queries. 另外,如果选择查询过多,请尝试使用缓存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM