M. php / vista-index.php

1
<?php
2
3
require_once __DIR__ . "/lib/manejaErrores.php";
4
require_once __DIR__ . "/lib/devuelveJson.php";
5
require_once __DIR__ . "/Bd.php";
6
7
$bd = Bd::pdo();
8
$stmt = $bd->query("SELECT * FROM PRODUCTO ORDER BY PROD_NOMBRE");
9
$lista = $stmt->fetchAll(PDO::FETCH_ASSOC);
10
11
$render = "";
12
foreach ($lista as $modelo) {
13
 $encodeId = urlencode($modelo["PROD_ID"]);
14
 $id = htmlentities($encodeId);
15
 $nombre = htmlentities($modelo["PROD_NOMBRE"]);
16
 $precio = htmlentities("$" . number_format($modelo["PROD_PRECIO"], 2));
17
 $existencias = htmlentities(number_format($modelo["PROD_EXISTENCIAS"], 2));
18
 $render .=
19
  "<dt>$nombre</dt>
20
    <dd>
21
     <a href='agrega.html?id=$id'>Agregar al carrito</a>
22
    </dd>
23
    <dd>
24
     <dl>
25
      <dt>Precio</dt>
26
      <dd>$precio</dd>
27
      <dt>Existencias</dt>
28
      <dd>$existencias</dd>
29
     </dl>
30
    </dd>";
31
}
32
devuelveJson(["lista" => ["innerHTML" => $render]]);
33
skip_previous skip_next