1
Good afternoon, everyone,
I have two data in the database, but doing select only 1 appears, pq?
<?php
ini_set('display_errors', true);
error_reporting(E_ALL);
include_once("con.php");
$pdo = conectar();
$opcao = $_GET['opcao'];
switch ($opcao) {
case 'pegaCategoria':
$pegaCategoria=$pdo->prepare("SELECT * FROM categoriaComum");
$pegaCategoria->execute();
$return = array();
while ($linhaCateAdmin=$pegaCategoria->fetch(PDO::FETCH_ASSOC)) {
$idcategoriaComum = $linhaCateAdmin['idcategoriaComum'];
$categoriaComum = $linhaCateAdmin['categoriaComum'];
$return = [
"idcategoriaComum" => $idcategoriaComum,
"categoriaComum" => $categoriaComum
];
}
echo json_encode($return);
break;
?>
And from the image below, you can see that I have two data in the table.
And on the console, it displays 1 only.
$return
is being reallocated all the time, you need to add a new item in the array.$return[] = ['chave' => valor]
– rray