-1
I’m having problems with paging, I have the main page where you can find the whole structure of my site, called main.php where there is the switch to open the files, so.
MAIN PAGE.PHP
switch(@ $_GET['pag'])
{ case "historico": include("historico.php"); break; ...
But the problem is in the historical page.php, where if I have there a form action with an input card name, where the person type the board and appears the data, until then everything OK, I made the pagination code, but when I click on the next page appears the input again, for me to enter the plate, after I type the plate that appears the page I clicked, being that the correct one was to load the next page without the need to type again in the input. Follows code from the history.php
PAGE HISTORY.PHP
<form action="" method="post">
<table border="0" cellpadding="0" cellspacing="0" id="id-form">
<tr>
<th valign="top">DIGITE A PLACA:</th>
<td>
<input name="placa" type="text" class="inp-form" autofocus placeholder="Digite Aqui" size="7" required maxlength="7" onkeyup="toUpper(this);" />
</td>
<td>
<div class="error-left"></div>
<div class="error-inner">Este campo é obrigatório.</div>
</td>
</tr>
</table>
</form>
<?php
if(isset($_POST['placa'])){
$placa = $_POST['placa'];
$_SESSION['placa'] = $placa;
$query = mysql_query("SELECT * FROM veiculos WHERE placa = '$placa' ");
$dados = mysql_fetch_array($query);
$busca = mysql_query("SELECT * FROM horarios WHERE placa = '$placa' ");
if(mysql_num_rows($query) == 0){
echo "
<div id=message-red><br>
<table border=0 width=100% cellpadding=0 cellspacing=0>
<tr>
<td class=red-left>Error. <a href=>Placa não existe no banco de dados, verifique se não há necessidade de cadastro do veículo.</a></td>
<td class=red-right><a class=close-red><img src=images/table/icon_close_red.gif alt= /></a></td>
</tr>
</table>
</div></p>";
} // fim do mysql_num_rows($query) == 0
elseif(mysql_num_rows($busca) == 0) {
echo "
<div id=message-red><br>
<table border=0 width=100% cellpadding=0 cellspacing=0>
<tr>
<td class=red-left>Error. <a href=>A placa informada ainda não possui registros de entrada e saída.</a></td>
<td class=red-right><a class=close-red><img src=images/table/icon_close_red.gif alt= /></a></td>
</tr>
</table>
</div></p>"; }
else {?>
<form method='post'>
<table border="0" width="100%" cellpadding="0" cellspacing="0" id="product-table">
<tr>
<th class="table-header-cabecalho line-left minwidth-1">Placa do Veículo</th>
<th class="table-header-cabecalho line-left minwidth-1">Nome do Motorista</th>
<th class="table-header-cabecalho line-left minwidth-1">RG</th>
<th class="table-header-cabecalho line-left minwidth-1">Empresa</th>
<th class="table-header-cabecalho line-left minwidth-1">Entrada</th>
<th class="table-header-cabecalho line-left minwidth-1">Saída</th>
<th class="table-header-cabecalho line-left minwidth-1">Nota</th>
</tr>
<?php
$limite = 5;
$pagina = @$_GET['pagina'];
if(!$pagina){
$pagina = 1;
}
$inicio = ($pagina * $limite) - $limite;
$linhas = "SELECT veiculos.placa, veiculos.nome_motorista, veiculos.rg, veiculos.empresa, horarios.obs, horarios.entrada, horarios.saida FROM veiculos INNER JOIN horarios ON veiculos.placa=horarios.placa where veiculos.placa = '$placa' ORDER BY horarios.id_hor DESC limit $inicio,$limite";
$query = mysql_query($linhas);
while($linhas = mysql_fetch_array($query)){
echo "<tr>";
echo "<td>".$linhas['placa']."</td>";
echo "<td>".$linhas['nome_motorista']."</td>";
echo "<td>".$linhas['rg']."</td>";
echo "<td>".$linhas['empresa']."</td>";
echo "<td>". date("d/m/Y - H:i:s",strtotime($linhas['entrada']))."</td>";
if($linhas['saida'] == 0){echo "<td><font size='+3' color='#CC0000'>Veículo na empresa</font></td>";}else { echo "<td>". date("d/m/Y - H:i:s",strtotime($linhas['saida']))."</td>";}
echo "<td>".$linhas['obs']."</td>";
echo "</tr>";
}
$total_registros = mysql_num_rows(mysql_query("SELECT veiculos.placa, veiculos.nome_motorista, veiculos.rg, veiculos.empresa, horarios.obs, horarios.entrada, horarios.saida FROM veiculos INNER JOIN horarios ON veiculos.placa=horarios.placa where veiculos.placa = '$placa'"));
$total_paginas = ceil($total_registros / $limite);
//exibe a paginação
for($i = 1; $i <=$total_paginas; $i++) {
echo "
<table border='0' cellpadding='0' cellspacing='0' id='paging-table'>
<tr>
<td>
<a href='?pag=historico&&pagina=$i'>".$i."</a>
</td>
</tr>
</table>";
}
?>
</table>
</form>
<!-- end paging................ -->
<div class="clear"></div>
<?php
} // fim do else $dados
} // fim do isset do $_POST
?>
Do you understand? I’m waiting for help.
Someone who can help me?
– Paulo Pimentel
It’s time to use PDO and better separate this code, at least views to one side and models to the other, your code is well mixed, it is difficult to maintain
– Marcelo Aymone
You can pass the board through the URL or save in session.. being a query parameter, I would use the URL
– Papa Charlie
And take that off
@$_GET...
useisset
to verify the variable– Papa Charlie