Asked  2 Years ago    Answers:  5   Viewed   72 times

How can I detect the latest updates made to a database and silently refresh a page when a change occurs?

Let's say the database access looks like:

$host = "localhost";
$username = "root";
$password = "root";
$db = mysql_connect($host,$username,$password) or die(mysql_error());
mysql_select_db('ccr') or die(mysql_error());

Any ideas and samples would be appreciated. Thank you.

 Answers

1

This is how I recently implemented a solution using jQuery.

PHP increments a field in the database every time a significant update occurs.

<?php

//  Call this function when data changes
function update_clients()
{
    mysql_query( "UPDATE pageGen SET id = id + 1 LIMIT 1" );
}

//  Call this function to get the ID to pass to JavaScript
function get_update()
{
    $result = mysql_query( "SELECT id FROM pageGen LIMIT 1" );
    $update = mysql_result( $result, 0, 'id' );
    return $update;
}

?>

When the page is initially loaded, populate a JavaScript variable with a number from the database:

<script type="text/javascript">
var pageGenID = 25218603  //  generated by PHP
var processUpdate = function( response ) 
{
    if ( pageGenID < response ) 
    {
        replace_current_data_with_new_via_ajax();
        pageGenID = response;
    }
}
//  Compare our Page Generate ID against that of the server
var checkUpdates = function()
{
    serverPoll = setInterval( function()
    {
        $.get('script_to_return_latest_pageGenID.php', 
          { lastupdate: 1 }, 
          processUpdate, 'html');
    }, 10000 )
};

//  Check for updates every 10 seconds
$( document ).ready( checkUpdates );

</script>
Friday, December 23, 2022
1

I have found out the way to get around this problem and I can imagine it could be an issue for other VistaPanel/cPanel users of phpMyAdmin.

I had to log into the cPanel, change my password, logout, clear all my cookies and then log back in. When I logged back in and tried to connect to phpMyAdmin I could get in fine!

Monday, August 29, 2022
2

You can also call anim.cancel(); but you should also call anim.reset(); immediately after it. Then when you want to start it again, just call startAnimation on the view.

Thursday, September 22, 2022
 
1

Had the same issue with PHPStorm on MAMP. Checked the port in localhost where MySQL was installed. It was 8889 and not the default 3306. Updating the port fixed the issue for me.

Friday, October 14, 2022
5

You should probably override your onResume() to check if the list of alarms have been refreshed so that whenever you come to/come back to your ListActivity, it'll get updated.

Saturday, November 26, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 

Browse Other Code Languages