Guest User

Untitled

a guest
Dec 13th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. import { Component, OnInit } from '@angular/core';
  2. import { ProductoServiceService } from '../producto-service.service';
  3. import "rxjs/add/operator/map";
  4.  
  5.  
  6. @Component({
  7. selector: 'app-listado',
  8. templateUrl: './listado.component.html',
  9. styleUrls: ['./listado.component.css']
  10. })
  11. export class ListadoComponent implements OnInit {
  12. filterargs;
  13. listado;
  14. items;
  15.  
  16. constructor(private crudProducto:ProductoServiceService) { }
  17.  
  18. ngOnInit() {
  19.  
  20. this.crudProducto.listar() //Llamamos a la funcion listar de nuestro servicio
  21. .map((response) => response.json()) //Mapeamos los datos devueltos por nuestro archivo php
  22. .subscribe((data) => {
  23. // console.log(data);
  24. this.listado = data; //Asignamos nuestros datos mapeados a una variable
  25. });
  26. }
  27.  
  28. }
  29.  
  30. <html xmlns="http://www.w3.org/1999/xhtml">
  31. <head>
  32. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  33. <title>Documento sin t&iacute;tulo</title>
  34. </head>
  35.  
  36. <body>
  37. <h4>LISTADO DE MIS PRODUCTOS</h4>
  38. <table>
  39. <thead>
  40. <tr>
  41. <th>DESCRIPCION</th>
  42. <th>FECHA</th>
  43. <th>P. COMPRA</th>
  44. <th>P. VENTA</th>
  45. </tr>
  46. </thead>
  47. <tbody>
  48. <tr *ngFor="let item of listado">
  49. <td >
  50. {{item.pro_descripcion}}
  51.  
  52. </td>
  53. </tr>
  54. </tbody>
  55. </table>
  56. </body>
  57. </html>
  58.  
  59. <?php
  60. header("Access-Control-Allow-Origin: *");
  61. header("Content-Type: application/json; charset=UTF-8");
  62.  
  63. $server = "localhost";
  64. $user = "root";
  65. $pass = "";
  66. $bd = "test";
  67.  
  68. //Creamos la conexión
  69. $conexion = mysqli_connect($server, $user, $pass,$bd)
  70. or die("Ha sucedido un error inexperado en la conexion de la base de datos");
  71.  
  72. //generamos la consulta
  73. $sql = "SELECT * FROM productos";
  74. mysqli_set_charset($conexion, "utf8"); //formato de datos utf8
  75.  
  76. if(!$result = mysqli_query($conexion, $sql)) die();
  77.  
  78. $clientes = array(); //creamos un array
  79.  
  80. while($row = mysqli_fetch_array($result))
  81. {
  82. $idproducto=$row['idproducto'];
  83. $pro_descripcion=$row['pro_descripcion'];
  84. $pro_unidad=$row['pro_unidad'];
  85. $pro_marca=$row['pro_marca'];
  86. $pro_fcompra=$row['pro_fcompra'];
  87. $pro_pcompra=$row['pro_pcompra'];
  88. $pro_pventa=$row['pro_pventa'];
  89. $pro_observaciones=$row['pro_observaciones'];
  90. $vigencia=$row['vigencia'];
  91.  
  92. $clientes[] = array('idproducto'=> $idproducto, 'pro_descripcion'=> $pro_descripcion, 'pro_unidad'=> $pro_unidad, 'pro_marca'=> $pro_marca, 'pro_fcompra'=> $pro_fcompra, 'pro_pcompra'=> $pro_pcompra, 'pro_pventa'=> $pro_pventa, 'pro_observaciones'=> $pro_observaciones, 'pro_vigencia'=> $pro_vigencia);
  93.  
  94.  
  95.  
  96. }
  97.  
  98. //desconectamos la base de datos
  99. $close = mysqli_close($conexion)
  100. or die("Ha sucedido un error inexperado en la desconexion de la base de datos");
  101.  
  102.  
  103. //Creamos el JSON
  104. $json_string = json_encode($clientes);
  105. echo $json_string;
  106. ?>
Add Comment
Please, Sign In to add comment