Using AJAX for an auto-refresh page containing values ​​from a database?

Can someone explain how to create a .php page that automatically updates values ​​from the database? Would using AJAX be better for something like that? I need this PHP code, but I want the page to be updated whenever "values01" is added or changed, without having to refresh the page. Any help would be appreciated! :)
$query = "SELECT values01 FROM users WHERE username='$username'";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo nl2br("{$row['values01']}");
}

+3
source share
1 answer

, , push- -. , , - ( , -, http push, , - ). .

, :

  • , "" . ( $_SESSION ['currentState']) . javascript ( , 10 ).
  • , AJAX script . script "updateValues.php". updateValues.php . $_SESSION ['currentState'], , (json, xml ..), $_SESSION ['currentState'] . , - .
  • javascript, , db, .
  • goto 2.

, push-, - 10- ( , ).

+2

Source: https://habr.com/ru/post/1756588/


All Articles