0
I found some practical errors running my code and don’t know how to fix it. Follow the code below:
<div id="divConteudo">
<?php
$con_string = "host='***' port=5432 dbname='***' user='***' password='***'";
$conn = pg_connect($con_string);
$query = "select pa_maquina, pa_hora - pa_inicioparada as tempo, pa_motivo, pa_data, pa_observacao from relatorioparadas";
$total_reg = "10"; // número de registros por página
$pagina=$_GET['pagina'];
"'?pagina='1'";
if (!$pagina) {
$pc = "1";
} else {
$pc = $pagina;
}
$inicio = $pc - 1;
$inicio = $inicio * $total_reg;
$limite = "$query LIMIT $total_reg offset $inicio";
$todos = pg_query("$query");
$tr = pg_num_rows($todos); // verifica o número total de registros
$tp = $tr / $total_reg; // verifica o número total de páginas
$anterior = $pc -1;
$proximo = $pc +1;
$output=pg_query($conn,$limite);
{ ?>
<table id="tabela">
<thead>
<tr>
<th><center>Máquina</center></th>
<th><center>Tempo de Parada</center></th>
<th><center>Motivo</center></th>
<th><center>Observações de Ocorrencia</center></th>
<th><center>Data</center></th>
</tr>
<tr>
<th><center><input type="text" id="txtColuna1"/></center></th>
<th><center><input type="text" id="txtColuna2"/></center></th>
<th><center><input type="text" id="txtColuna3"/></center></th>
<th><center><input type="text" id="txtColuna4"/></center></th>
<th><center><input type="text" id="txtColuna5"/></center></th>
</tr>
</thead>
<tbody>
<tr>
<?php
while ($result = pg_fetch_array($output)) {
$maquina = $result["pa_maquina"];
$tempo = $result["tempo"];
$motivo = $result["pa_motivo"];
$data = $result["pa_data"];
$observacao = $result["pa_observacao"];
echo '<td>'; echo $result["pa_maquina"]; echo'</td>';
echo '<td>'; echo $result["tempo"]; echo'</td>';
echo '<td>'; echo $result["pa_motivo"]; echo'</td>';
echo '<td>'; echo $result["pa_observacao"]; echo'</td>';
echo '<td>'; echo $result["pa_data"]; echo'</td>';
echo'</tr>
</tbody>'; }?>
</table>
<?php } ?>
</div>
<div class="row x_title text-right">
<input type= "submit" id="visualizarDados" value="OK">
<?php
if ($pc>1) {
echo "<a href='?pagina=$anterior'><button><- Anterior</button></a> ";
}
if ($pc<$tp) {
echo " <a href='?pagina=$proximo'><button>Próxima -></button></a>";
}
?>
</div>
<script>
$(function(){
$("#tabela input").keyup(function(){
var index = $(this).parent().index();
var nth = "#tabela td:nth-child("+(index+1).toString()+")";
var valor = $(this).val().toUpperCase();
$("#tabela tbody tr").show();
$(nth).each(function(){
if($(this).text().toUpperCase().indexOf(valor) < 0){
$(this).parent().hide();
}
});
});
$("#tabela input").blur(function(){
$(this).val("");
});
});
</script>
First error: loading the page says that the page variable was not set, even with that "if" just below. When I click next, the error disappears. Second error: The filter is only working for the first column, when it should filter the column where it is being typed. Here is a picture of the table:
The filter code I noticed from this tutorial: http://www.linhadecodigo.com.br/artigo/3511/criando-um-filtro-automatico-nas-colunas-de-uma-tabela-html.aspx
I am beginner in the area and accept any suggestion.