0
I am making a simple query via getJSON, but it is not returning the values to be shown.
Filing cabinet testeJson.php
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Documento sem título</title>
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script>
$(document).ready(function() {
//$("#email").click(function() {
nome = "listar";
$.getJSON("testeConexaoMobileJson.php", {acao:nome}, function(json){
$("#nome").val(json[0].nome);
$("#email").val(json[0].email);
});
//});
});
</script>
</head>
<body>
<h1>Cardápio de Pizzas</h1>
<div id="email"></div>
<input type="text" name="nome" id="nome">
</body>
</html>
Filing cabinet testMobileJson.php
<?php
$mysqli = new mysqli('localhost','','',''); if($mysqli->connect_error){echo "Erro";exit();}
if($_GET['acao'] == 'listar'){
header('Content-Type: application/json; charset=utf-8');
$rs = $mysqli->query("SELECT * FROM cadastro");
$row_rs = $rs->fetch_assoc();
$row = $rs->fetch_array();
$registros = mysqli_num_rows($rs);
while($campos=mysqli_fetch_array($rs)) {
extract($campos);
$Array = Array();
$Array[] = Array(
"nome" => "$nome",
"email" => "$email",
);
$json_encode = json_encode($Array);
echo $json_encode;
}
}
?>
Result of the testConexaoMobileJson.php file
Upshot:
[{"name":"Tiago","email":"[email protected]"}][{"name":"Tiago","email":"[email protected]"}]
I agree. That
extract
there could generate debug weeks without understanding why such a variable is with such value– Wallace Maxters
I tested and worked, but appeared all the tables of the comic, how do I show only what I want? Leave the one you created above because it is very useful for other people.
– Tiago
I understood, but I asked to give a second example showing only the fields I need, but without using the
extract
, but doing the right way as shown in the first code.– Tiago
@rray Joia thank you very much.
– Tiago
kkkkkkkkkkkkkkkkkkkkkkkkkkkkk, I thought of everything but
SELECT
, kkkkkk– Tiago