-1
<!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>
see in the last 8 lines returns me an Alert more without data in the variables only returns it is that I need to work with this data in a js understand.
you know how I can pass these vlores to the js?
The important question here is: why do you want to display a Javascript alert with the HTML <td> tag? Or, if this alert should be inside while to get the $Row['name'], why do you want to display a Javascript alert for each line of the query? Makes no sense.
– Walter Gandarella
is that I want to use this data in a user panel the Alert is just to know if you have how to pass the value pro js.
– adailton moraes