sorry for my bad english google help me :-) with my script, if i enter something in the database, it is displayed without a page reload. Now I wanted to ask if this is so good or can it be improved? I know javascript/Ajax and what's not out there. I just want that if something is written into the db with a form, it's displayed immediately without page reload, like a kind of shoutbox.
<!DOCTYPE html>
<html lang="de" dir="ltr">
<head>
<meta charset="utf-8">
<title>Ausgabe</title>
</head>
<body onload = "table();">
<script type="text/javascript">
function table(){
const xhttp = new XMLHttpRequest();
xhttp.onload = function(){
document.getElementById("table").innerHTML = this.responseText;
}
xhttp.open("GET", "system.php");
xhttp.send();
}
setInterval(function(){
table();
}, 1);
</script>
<div id="table">
</div>
</body>
</html>
<?php
$host_name = '';
$database = '';
$user_name = '';
$password = '';
$link = new mysqli($host_name, $user_name, $password, $database);
if ($link->connect_error) {
die('<p>Verbindung zum MySQL Server fehlgeschlagen: '. $link->connect_error .'</p>');
}
$rows = mysqli_query($link, "SELECT * FROM tb_data");
?>
<table border = 1 cellpadding = 10>
<tr>
<td>#</td>
<td>Name</td>
</tr>
<?php $i = 1; ?>
<?php foreach($rows as $row) : ?>
<tr>
<td><?php echo $i++; ?></td>
<td><?php echo $row["name"]; ?></td>
</tr>
<?php endforeach; ?>
</table>