Results 1 to 6 of 6

Thread: How to refresh a form containing table in PHP?

  1. #1
    Join Date
    May 2011
    Posts
    55

    How to refresh a form containing table in PHP?

    I have developed a PHP page which contains many forms. In my one of the form there is a table which is having data in it. I want my form that is containing this table to be updated after a fixed interval. I don’t want to refresh all the forms of the table. Is there any way by which I can only update this form and not the entire form? Actually I want the table that displays data from the database to be updated for every minute automatically.

  2. #2
    Join Date
    May 2009
    Posts
    527

    Re: How to refresh a form containing table in PHP?

    Making the browser to cache XML files is not a bad idea. To generate XML, create a query and make it to run only whenever the database is updated. Don’t run the query to load the page. You need to turn off the cache if you want your table to get the updated information from the table for every single minute. It is also depended on the size of the database you are having. Also write a query for XML file that is only for updating the database.

  3. #3
    Join Date
    Apr 2009
    Posts
    488

    Re: How to refresh a form containing table in PHP?

    You can add the following lines of code at the end of your PHP page:

    <script language="javascript">
    window.setTimeout("self.location.href='<?=$PHP_SELF ?>'", 60000);
    </script>
    You can see that there is a single quote (‘) after the ?> followed by the double quotes (“)
    You can add the variables in the page. You can do this by adding it after the ?>. for ex ?id=98765 and so on.

  4. #4
    Join Date
    May 2009
    Posts
    539

    Re: How to refresh a form containing table in PHP?

    Try using AJAX, as AJAX gives a call to the PHP script. It then generates a HTML table. The existing table is by the table created by the PHP script. You can also make use of the META tag. Whenever the page refreshes you can send this Meta tag. This will help you to keep the page to update continuously. You can try these two lines of code in your page:

    <meta http-equiv="refresh" content="60;url=<?php echo $PHP_SELF; ?>">
    <meta http-equiv="refresh" content="60;url=<? echo $_SERVER['PHP_SELF'] ?>">

  5. #5
    Join Date
    Apr 2009
    Posts
    569

    Re: How to refresh a form containing table in PHP?

    Another solution is of using IIFE, which is used to set the setInterval. IIFE stands for Immediately-Invoked Function Expression. You can use the following lines of code using IIFE:

    var $results = $('#results'),
    loadInterval = 5000;
    (function loader() {
    $.get('script.php', function(html){
    $results.hide(200, function() {
    $results.empty();
    $results.html(html);
    $results.show(200, function() {
    setTimeout(loader, loadInterval);
    });
    });
    });
    })();

  6. #6
    Join Date
    May 2009
    Posts
    529

    Re: How to refresh a form containing table in PHP?

    You will need to have the getTable.PHP to display the content of the table. You can have the following code to make your table content to refresh for the time interval you want.
    <script type="text/javascript">
    $(document).ready(function(){
    refreshTable();
    });

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

    Here, refreshTable() variable is used to refresh the content of your table.

Similar Threads

  1. Automatically refresh pivot table on MS excel
    By Genna in forum Windows Software
    Replies: 6
    Last Post: 10-07-2011, 11:13 AM
  2. Replies: 5
    Last Post: 25-05-2011, 10:21 PM
  3. Replies: 2
    Last Post: 02-05-2011, 07:06 AM
  4. Link a Table to another Table to Drop Down In Main Table
    By himeshRES in forum Windows Software
    Replies: 6
    Last Post: 11-12-2010, 02:01 PM
  5. Problem reloading MDI child form in main form.
    By AFFAN in forum Software Development
    Replies: 3
    Last Post: 30-01-2009, 09:05 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,718,158,628.74426 seconds with 16 queries