I have a query in PHP
Model
public static function mostrarSlideIDModel($datosModel, $tabla){
$stmt = Conexion::conectar()->prepare("SELECT id_slide, marca_slide, desc_slide, liga_slide, imagen_slide FROM $tabla WHERE id_slide = :id");
$stmt -> bindParam(":id", $datosModel["id"], PDO::PARAM_INT);
$stmt -> execute();
return $stmt -> fetch();
$stmt -> close();
}
Controller:
public static function mostrarSlideIDController(){
$datosController = array("id" => $_POST['idSlide']);
$respuesta = SlideModel::mostrarSlideIDModel($datosController, "slides");
echo json_encode($respuesta);
}
and when viewing in the browser, in the AJAX response, it prints the information twice, one with the index and the other with the name of the column.
Example:
"0":48,
"1":"Nets",
"2":"Optiviework",
"3":"http://www.lorem.com/marcas/file.php",
"4":"banner-131.jpg",
"id_slide":48,
"marca_slide":"Nets",
"desc_slide":"Optiviework",
"liga_slide":"http://www.lorem.com/marcas/file.php",
"imagen_slide":"banner-131.jpg"
I don't know how correct this could be, these are the first times I've handled data in JSON. I hope someone can guide me, Thank you.
The problem is that the function
fetch
uses a parameter whose default value returns an associative array and an array with indices. If you want to see only one of these two options, you need to specify the parameter like this: