0

I am amending some results tables that display rows from a mysql database to refresh automatically. I am new to this so have based it on Refresh a table with jQuery/Ajax every 5 seconds

This works fine and I have tested it by asking for making the request to the server display the time so i can see the change when the refresh occurs.

My problem is that if i apply this to a table dislaying returned sql results (also using the jquery tablesorter). Both my sql and jquery fail unless I move all the files and code they are dependant upon to the php page i echo the table on. This is now making my pages a mess. So what is the best way to refresh and manage a results table with ajax and where should dependant files/code be located?

cheers

Community
  • 1
  • 1
user1222646
  • 123
  • 1
  • 2
  • 9
  • There's 3-4 different solutions on the page you've linked to - can you give us some of your code to look at? In particular, the function loading the data and repopulating the table. – Juffy Nov 06 '12 at 00:45
  • The solution ive used is the accepted answer. I havent used functions for the data. The SQL was just at the top of the page, results were echoed into a table in the – user1222646 Nov 06 '12 at 00:51
  • I am not sure what you mean by you have to move all your files and code to the page you echo the table on. You should likely have a PHP script which does nothing but gave you table data (or maybe table HTML source if you don't want to build the HTML in javascript). When you make AJAX call, you would just pull in the new data and display it. – Mike Brant Nov 06 '12 at 00:55

1 Answers1

0
    <script type="text/javascript">
    $(document).ready(function(){
      refreshTable();
    });

    function refreshTable(){
        $('#tableHolder').load('getTable.php');
        setInterval(refreshTable, 5000);
    }
</script>
ursuleacv
  • 1,119
  • 14
  • 16
  • `setInterval()` may be what you're thinking of to refresh every 5 seconds, `setTimeout()` only executes once. – Peter Oram Nov 06 '12 at 01:48