Guest User

Untitled

a guest
Mar 13th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.19 KB | None | 0 0
  1. //Construcción del formulario Filtro de Animales
  2. <form type="submit" method="post" role="form-horizontal" id="form-fil">
  3. <div class="form-group" style="font-size:12px">
  4.  
  5. <div class="col-sm-2" id="tittle">
  6. <h1><b>FORMULARIO ANIMALES POR LOCALIDAD </b> <br><b>Clave localidad: <?php $idLocalidad = $_GET['idLocalidad']; echo $idLocalidad?> </b></h1>//Cabe aclarar que esta clave la estoy mandando desde otra página por un url Get y aquí la obtengo y la imprimo
  7. </div>
  8.  
  9. <div class="col-sm-3">
  10. <label for="sel3">Animales: </label>//Construyo mi combo
  11.  
  12. <select class="form-control" name="selAnimal" id="selAnimal" >
  13. <?php
  14.  
  15. $query="select * from animales;";
  16. $result = pg_query($query) or die('Query failed: ' . pg_last_error());
  17. $rows = pg_num_rows ($result);
  18. $i = pg_num_fields($result);
  19.  
  20.  
  21. while ($line = pg_fetch_array($result)){
  22. if ($line[0] <> "") {
  23. echo "<option value='$line[0]' >$line[1]</option>";
  24. }
  25. else{
  26. echo"<option >&nbsp;</option>";
  27. }
  28. }
  29. ?>
  30.  
  31. </select>
  32. </div>
  33.  
  34. <div class="col-sm-2">
  35. <button type="button" class="btn btn-default" name="filtrar" value="Filtrar" id="buttonFiltro" onClick="showTableAnimales();">Filtrar </button>
  36.  
  37. </div>
  38. </form>
  39. // Panel para mostrar la tabla de la consulta
  40. <form method="post" class="form-horizontal">
  41. <div class="panel">
  42.  
  43. <div id="theTable"><b>Filtre el tipo de animal que desea consultar</b></div>
  44.  
  45. </div>
  46. </form>
  47.  
  48. function showTableAnimales() {
  49. r=document.getElementById("selAnimal").value;//almacena la respuesta del list (el tipo de animal)
  50.  
  51. console.log("ANIMALES" + r);
  52.  
  53. if (window.XMLHttpRequest) {
  54. // code for IE7+, Firefox, Chrome, Opera, Safari
  55. xmlhttp=new XMLHttpRequest();
  56. } else { // code for IE6, IE5
  57. xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  58. }
  59. xmlhttp.onreadystatechange=function() {
  60. if (this.readyState==4 && this.status==200) {
  61. document.getElementById("theTableApoyados").innerHTML=this.responseText;
  62.  
  63.  
  64. }
  65. }
  66. xmlhttp.open("POST","includes/getTableAnimales.php?r="+r,true);
  67.  
  68. xmlhttp.send();
  69. }
  70.  
  71. <?php
  72.  
  73. $host = "localhost";
  74. $db = "animales";
  75. $user = "postgres";
  76. $pw = "admin";
  77. $port = "5432";
  78.  
  79. $packedString = "host=" . $host . " dbname=" . $db . " user=" . $user . " password=" . $pw . " port=" . $port;
  80.  
  81.  
  82. $dbconn = pg_connect($packedString)or die('Could not connect: ' . pg_last_error());
  83. session_start();
  84.  
  85. $r = intval($_GET['r']);
  86. $query="select count (animal)
  87. from animales a, localidades l
  88. where a.c_animal in($r) and id_localidad = '$idLocalidad' //esto es lo que necesito PERO NO SE COMO TRAER AQUÍ MI VARIABLE $ID_LOCALIDAD
  89. group by a.animal;";
  90.  
  91. $result = pg_query($query) or die('Query failed: ' . pg_last_error());
  92. $rows = pg_num_rows ($result);
  93. $i = pg_num_fields($result);
  94.  
  95. echo "<table class='table table-fixed' border=1> <thead><tr> ";
  96. for($j=0; $j<$i; $j++){
  97. $fieldname=pg_field_name($result, $j);
  98. echo "<th>".strtoupper($fieldname)."</th>"; //columns
  99.  
  100. }
  101. echo "</tr> </thead>"
  102. ?>
  103.  
  104.  
  105.  
  106. <?php
  107. echo "<tbody>";
  108. while ($line = pg_fetch_array($result)){
  109. echo "<tr>";
  110. for($j=0; $j<$i; $j++){
  111. if ($line[$j] <> "") {
  112. echo "<td>$line[$j]</td>";
  113.  
  114. }
  115. else{
  116. echo"<td >&nbsp;</td>";
  117. }
  118. }
  119. echo "</tr>";
  120. }
  121. echo "</tbody>";
  122. echo "</table>";
  123.  
  124. ?>
Add Comment
Please, Sign In to add comment