Hello, I have a function that returns an array but I want to access by means of its indexes to the value that I want from the selected fields in the database, for example, to save the variable at the index [0] in other words the first value of the arrangement and in the variable b save the index [1] and so on. This is my code I thought working with arrays was a matter of using indexes.
class Tabla{
public function salida_materiales() {
try {
$orden_de_compra = $_GET['orden_de_compra'];
include("resource/Database.php");
$sql = "SELECT folio, fecha, numero_remision ,numero_factura,otro,referencia_transporte ,placa_tractor,placa_caja,comentarios,retorno,
fecha_posible FROM salida_materiales WHERE orden_de_compra= :orden_de_compra";
$query = $db->prepare($sql);
$query->bindparam(':orden_de_compra', $orden_de_compra);
$query->execute();
$tabla = $query->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
//echo "Exeption: " .$e->getMessage();
$result = false;
}
$query = null;
$db = null;
return $tabla;
}
}
I call the function and it does not save the value
$tabla = new Tabla();
$arreglo = $tabla->salida_materiales();
$folio = $arreglo[0];
and so if I wanted more variables from the array obtained by the query, by the way I already protected my code against the sql injection thanks to the recommendation of a user of this page.