简体   繁体   English

如何更新由php / mysql生成的表的一列没有重新加载页面/表?

[英]how to update just one column of table generatedy by php/mysql with out reloading page/table?

So I have the following HTML table being generated with php getting data from a mysql table. 因此,我使用php从mysql表中获取数据生成以下HTML表。 And what I want to do is constantly update just that last row using ajax so that the table doesn't reload the entire table. 而我想要做的是使用ajax不断更新最后一行,以便表不会重新加载整个表。

<tbody>
                    <?php while($row = MySQL_fetch_array($result)):
                    $id = htmlentities($row['id']);
                    $status = htmlentities($row['status']);
                    include ("button.php");
                    ?>
                    <tr>
                        <td title="lname" width="100px">
                            <div style="width:100px; overflow:hidden;">
                                <?php echo(htmlentities($row['last_name'])); ?>
                            </div>
                        </td>
                        <td width="100px">
                            <div style="width:100px; overflow:hidden;">
                                <?php echo(htmlentities($row['first_name'])); ?>
                            </div>
                        </td>    
                        <td width="100px">
                            <div style="width:100px; overflow:hidden;">
                                <?php echo(htmlentities($row['u_name'])); ?>
                            </div>
                        </td>  
                        <td width="100px">
                            <div style="width:150px; overflow:hidden;">
                                <?php echo(htmlentities($row['skype_id'])); ?>
                            </div>
                        </td>
                        <td width="100px">
                            <div style="width:100px; overflow:hidden;">
                                <?php echo(htmlentities($row['primary_location'])); ?>
                            </div>
                        </td>
                        <td>
                            <div style="width:100px; overflow:hidden;">
                                <?php echo(htmlentities($row['phone'])); ?>
                            </div>
                        </td>
                        <td>
                            <div style="width:100px; overflow:hidden;">                                     
                                <?php echo '<div><div id="r'.$id.'"><div id="test"><img class="rating" id="'.$status.$id.'" src="'.$color.'"><div style="display:none;">'.$status.'</div></div></div></div>';?>
                            </div>
                        </td>
                    </tr>                       
                    <?php endwhile; ?>
                </tbody>

I tried doing the following: 我尝试过以下操作:

<script>
$(document).ready(function(){
  refreshTable();
});

function refreshTable(){
    $('#test').load('response.php', function(){
       setTimeout(refreshTable, 5000);
    });
}
</script>

Where response.php just had the entire while loop again. response.php再次使用整个while循环。 The problem with this were the following: 这个问题如下:

1) After a few seconds, the page would get slower and slower...less and less responsive. 1)几秒钟后,页面会越来越慢......响应越来越少。 And soon it would just grind to a halt. 很快它就会陷入停顿。 I have no idea why. 我不知道为什么。

2) The refresh is visible. 2)刷新是可见的。 All the table highlight blinks off for a moment at each refresh. 每次刷新时,所有表格突出显示都会闪烁一下。

So I thought, maybe if I just try refreshing the one column...it wouldn't grind to a halt? 所以我想,也许如果我只是尝试刷新一列......它会不会停止? However, ever attempt I made to just update the column broke everything, all my scripts would stop working. 但是,我曾试图只更新列,打破了一切,我的所有脚本都会停止工作。 And I'm not sure how to get rid of the issue of the table highlighting disappearing at refresh. 我不知道如何摆脱表突出显示在刷新时消失的问题。 How can I get this all to work? 我怎样才能让这一切都奏效?

Thanks! 谢谢!

Make an ajax request to a URL which only returns the last row in json (or html, surrounded by the <tr> tags of course) format. 对URL进行ajax请求,该URL仅返回json(或html中的最后一行,当然包含<tr>标记)格式。 Then, replace the last row using javascript. 然后,使用javascript替换最后一行。

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

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