I've got a page that retrieves two values from the database (Atender and Posto).
I'd like to refresh a textbox1 with Atender value and textbox2 with Posto value. At the moment, I'm only able to make it so this function refreshes 1 value or the 2 values simultaneously, but both values show up on the two textboxes.
EDIT: Forgot to add, the PHP you see there is the PainelUtilizador.php. Same goes for the HTML, all of that code is inside PainelUtilizador.php
Here's my code, I'm sure you'll be able to know what I mean after taking a look:
<?php
include '../Login/db_login.php';
if(isset($_GET['ajax'])) {
$sql1 = "SELECT Atender,Posto FROM atendercliente WHERE ID=1";
$sql2 = "SELECT Atender,Posto FROM atendercliente WHERE ID=2";
$resultA = $conn->query($sql1);
while($row = $resultA->fetch_assoc()) {
$returnArrayA = array('AtenderA' => $row["Atender"], 'PostoA' => $row["Posto"]);
};
$resultB = $conn->query($sql2);
while($row = $resultB->fetch_assoc()) {
$returnArrayB = array('AtenderB' => $row["Atender"], 'PostoB' => $row["Posto"]);
};
echo json_encode($returnArrayA);
echo json_encode($returnArrayB);exit;
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Painel do utilizador</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
setInterval(function(){
$.ajax('PainelUtilizador.php?ajax=1').done(function(data) {
data = JSON.parse(data);
$("#refreshASenha").val(data['Atender']);
$("#refreshAPosto").val(data['Posto']);
$("#refreshBSenha").val(data['Atender']);
$("#refreshBPosto").val(data['Posto']);
})
}, 1000);
</script>
</head>
<body>
<table border="1">
<tr>
<td> <input type="text" id="refreshASenha" disabled> </td>
<td> <input type="text" id="refreshAPosto" disabled> </td>
</tr>
</table>
<table border="1">
<tr>
<td> <input type="text" id="refreshBSenha" disabled> </td>
<td> <input type="text" id="refreshBPosto" disabled> </td>
</tr>
</table>
</body>
</html>
I'm still a beginner, and am still learning AJAX and JQuery by myself
PainelUtilizador.php