<!DOCTYPE html>
<html>
<head>
<style>
table {
width: 100%;
border-collapse: collapse;
}
table, td, th {
border: 1px solid black;
padding: 5px;
}
th {text-align: left;}
</style>
</head>
<body>
<?php
$q = intval($_GET['q']);
$con = mysqli_connect('localhost','peter','abc123','my_db');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"banco_dados");
$sql="SELECT * FROM usuario WHERE id = '".$q."'";
$result = mysqli_query($con,$sql);
echo "<table>
<tr>
<th>nome</th>
<th>snome</th>
<th>idade</th>
<th>cidade</th>
<th>estado</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['nome'] . "</td>";
echo "<td>" . $row['snome'] . "</td>";
echo "<td>" . $row['idade'] . "</td>";
echo "<td>" . $row['cidade'] . "</td>";
echo "<td>" . $row['estado'] . "</td>";
echo "</tr>";
$json[] = $row;
}
echo "</table>";
mysqli_close($con);
$teste = $row['nome'];
?>
<script type="text/javascript">
var dados = <?php echo json_encode($json)?>;
alert(dados[2].nome);
</script>
</body>
</html>
look at the last 8 lines returns me an alert plus no data in the variables so it returns this is that I need to work with this data in a js understand.
You know how I can pass these vlores to js?