php - Using AJAX for an auto-updating page containing values from a database? -


can explain how create .php page auto-updates values database? using ajax best this? want php code, want page updated whenever 'values01' added or changed, without having refresh page.
$query = "select values01 users username='$username'";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, mysql_assoc))
{
echo nl2br("{$row['values01']}");
}

appreciated! :)

what describing push notification web server. unfortunately, have not found reliable way traditional push, web server initiate connection client (from limited research, appears there proposals http standard support push, however, doesn't adopted standard ever emerged). however, can done in bit more roundabout way.

there way around push limitation typically used:

  1. browser connects page, loads current "state" of database. session variable (lets call $_session['currentstate']) saved starting state of database. javascript timer on client's browser starts ticking down (lets timer 10 seconds long).
  2. once timer expires, ajax call made script on server. lets call script "updatevalues.php". updatevalues.php checks new state of database. if database differs $_session['currentstate'], return whatever changes have been made, in nice form (json, xml, etc..), , update $_session['currentstate'] new state. if there no change, reply extent.
  3. upon receiving data, browser executes javascript updates rendering in browser if changes have been made db, , restarts timer.
  4. goto 2.

the thing missing here typical push notification, 10-second (or whatever choose timer) lag.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -