0
I need to return the data in an array. I’m doing it, but the data doesn’t return:
<?php
ini_set('display_errors', true);
error_reporting(E_ALL);
include_once("conexao.php");
$pdo = conectar();
header('Content-Type: application/json');
header("Access-Control-Allow-Origin: *");
/*$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
$idCategoria = $request->idCategoria;*/
$id_categoria = $_GET['idCategoria'];
echo $id_categoria;
$buscarSubcategoria=$pdo->prepare("SELECT * FROM sub_cat_entrada WHERE id_categoria = :id_categoria");
$buscarSubcategoria->bindValue(':id_categoria', $id_categoria, PDO::PARAM_INT);
$buscarSubcategoria->execute();
//$buscarSubcategoria->debugDumpParams();
$return = array();
while ($linha=$buscarSubcategoria->fetch(PDO::FETCH_ASSOC)) {
$return[] = array(
'id_subcategoria' => $linha['id_subcategoria'],
'subcategoria' => utf8_encode($linha['subcategoria']),
);
}
echo json_encode($return);
Your query return a line or more?
– rray
More than one line.
– GustavoSevero
That’s how it works?
while ($linha=$buscarSubcategoria->fetch(PDO::FETCH_ASSOC)) {
 $return[] = $linha; 
}
– rray
No, only the 1 of the echo $id_categoria appeared;
– GustavoSevero
If you give a
print_r($return)
ve the array correctly? this goes for a javascript?– rray
Go pro angular, this result. Gave the print_r($Return) and appeared the data and array "tree" format. I’m running the code on Chrome’s POSTMAN to test.
– GustavoSevero
Is the problem not on the javascript side?
– rray
I put my angular return code in the description of the post @rray
– GustavoSevero
I found the problem. The data does not appear because it has accented words. ?
– GustavoSevero
I got... The two drop-down working. .
– GustavoSevero