Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Construcción del formulario Filtro de Animales
- <form type="submit" method="post" role="form-horizontal" id="form-fil">
- <div class="form-group" style="font-size:12px">
- <div class="col-sm-2" id="tittle">
- <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
- </div>
- <div class="col-sm-3">
- <label for="sel3">Animales: </label>//Construyo mi combo
- <select class="form-control" name="selAnimal" id="selAnimal" >
- <?php
- $query="select * from animales;";
- $result = pg_query($query) or die('Query failed: ' . pg_last_error());
- $rows = pg_num_rows ($result);
- $i = pg_num_fields($result);
- while ($line = pg_fetch_array($result)){
- if ($line[0] <> "") {
- echo "<option value='$line[0]' >$line[1]</option>";
- }
- else{
- echo"<option > </option>";
- }
- }
- ?>
- </select>
- </div>
- <div class="col-sm-2">
- <button type="button" class="btn btn-default" name="filtrar" value="Filtrar" id="buttonFiltro" onClick="showTableAnimales();">Filtrar </button>
- </div>
- </form>
- // Panel para mostrar la tabla de la consulta
- <form method="post" class="form-horizontal">
- <div class="panel">
- <div id="theTable"><b>Filtre el tipo de animal que desea consultar</b></div>
- </div>
- </form>
- function showTableAnimales() {
- r=document.getElementById("selAnimal").value;//almacena la respuesta del list (el tipo de animal)
- console.log("ANIMALES" + r);
- if (window.XMLHttpRequest) {
- // code for IE7+, Firefox, Chrome, Opera, Safari
- xmlhttp=new XMLHttpRequest();
- } else { // code for IE6, IE5
- xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
- }
- xmlhttp.onreadystatechange=function() {
- if (this.readyState==4 && this.status==200) {
- document.getElementById("theTableApoyados").innerHTML=this.responseText;
- }
- }
- xmlhttp.open("POST","includes/getTableAnimales.php?r="+r,true);
- xmlhttp.send();
- }
- <?php
- $host = "localhost";
- $db = "animales";
- $user = "postgres";
- $pw = "admin";
- $port = "5432";
- $packedString = "host=" . $host . " dbname=" . $db . " user=" . $user . " password=" . $pw . " port=" . $port;
- $dbconn = pg_connect($packedString)or die('Could not connect: ' . pg_last_error());
- session_start();
- $r = intval($_GET['r']);
- $query="select count (animal)
- from animales a, localidades l
- 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
- group by a.animal;";
- $result = pg_query($query) or die('Query failed: ' . pg_last_error());
- $rows = pg_num_rows ($result);
- $i = pg_num_fields($result);
- echo "<table class='table table-fixed' border=1> <thead><tr> ";
- for($j=0; $j<$i; $j++){
- $fieldname=pg_field_name($result, $j);
- echo "<th>".strtoupper($fieldname)."</th>"; //columns
- }
- echo "</tr> </thead>"
- ?>
- <?php
- echo "<tbody>";
- while ($line = pg_fetch_array($result)){
- echo "<tr>";
- for($j=0; $j<$i; $j++){
- if ($line[$j] <> "") {
- echo "<td>$line[$j]</td>";
- }
- else{
- echo"<td > </td>";
- }
- }
- echo "</tr>";
- }
- echo "</tbody>";
- echo "</table>";
- ?>
Add Comment
Please, Sign In to add comment