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