Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Ola pessoal, estou precisando de uma força de voces .. é o seguinte, tenho um sistema de buscar na página, e na mesma página tenho um sistema de paginação ..
a paginação funciona normalmente quando nao busco por nada .. porem quando faço uma busca que da resultados com mais de uma página, nao da certo. Queria continuar a segunda página com o que eu digitei no buscar.. entenderam ? oque posso fazer ?
meu código esta ai embaixo
<form style="font-size: 13px;" name="FormPesquisa" action="estoque.php" method="post">
<table width="99%" style="font-size: 13px;">
<tr>
<td width="10%" style="font-family: verdana; font-weight: bold;">CÓDIGO</td>
<td colspan="2" style="font-family: verdana; font-weight: bold;">NOME DO ITEM</td>
</tr>
<tr>
<td width="10%"><input type="text" id="txtcodigo" name="txtcodigo" style=" border: 1px gray solid; padding: 2px; text-transform: uppercase;" maxlength="15" size="15" onkeydown="bloquearCtrlJ();"></td>
<td><input type="text" name="txtnome" style=" border: 1px gray solid; padding: 2px; text-transform: uppercase;" maxlength="100" size="50">
<input type="submit" value=" PESQUISAR " style="font-family: verdana; padding: 2px; background-color: gray; color: white; font-weight: bold;" name="enviar" ></td>
<td align="right"><input type="button" style=" font-weight: bold; font-family: verdana; padding: 2px; background-color: gray; color: white;" value=" IMPRIMIR " name="enviar" onclick="window.open('imprimirEstoqueM.php','_blank');"></td>
</tr>
</table>
</form>
<table width="99%" style="font-size: 13px;">
<tr>
<td colspan="3" style="font-size: 13px;"><br>Filtrando de 8 em 8</td>
</tr>
<tr bgcolor="gray">
<td width="8%" align="center" style="font-weight: bold; color: white">CÓDIGO</td>
<td width="40%" align="center" style="font-weight: bold; color: white">ITEM</td>
<td width="5%" align="center" style="font-weight: bold; color: white">QNTD</td>
<td width="11%" align="center" style="font-weight: bold; color: white">CST UND (R$)</td>
<td width="11%" align="center" style="font-weight: bold; color: white">CST TOT (R$)</td>
<td width="11%" align="center" style="font-weight: bold; color: white">VR VENDA (R$)</td>
<td width="11%" align="center" style="font-weight: bold; color: white">VR TOTAL (R$)</td>
</tr>
</table>
<table cellspacing="0" width="99%" style="font-size: 13px;background: white;" class="table">
<?php
$mensagem = "";
include_once '../../conexaobd/conexaobd.php'; // chama a conexao com o bando de dados
if ( isset( $_POST["txtnome"] ) ){$pesq = $_POST["txtnome"];} else { $pesq = "";}
if ( isset( $_POST["txtcodigo"] ) ){$codigo = $_POST["txtcodigo"];} else { $codigo = "";}
#Consulta a ser feita no MySQL
if ( $pesq == "" && $codigo == ""){
$sql = "SELECT *
FROM item
WHERE estoqueT <= estoqueM AND nome LIKE '%$pesq%'
ORDER BY nome";
}else
if( $codigo == ""){
$sql = "SELECT *
FROM item
WHERE estoqueT <= estoqueM AND nome LIKE '%$pesq%'
ORDER BY nome";
}else
if( $pesq == ""){
$sql = "SELECT *
FROM item
WHERE estoqueT <= estoqueM AND coditem LIKE '$codigo'
ORDER BY nome";
}
#Número de registros paginados por página
$registros_pagina = "8";
#Resgatamos a página que estiver sendo acessada pela paginação
if ( isset( $_GET["lista"] ) ){$lista = (int)$_GET["lista"];} else { $lista = NULL;}
#Se for a página inicial da consulta, a variável $lista será nula
if(!$lista) {
$pc = "1";
}
#Caso contrário, declaramos o valor atual da variável $lista
else {
$pc = $lista;
}
$inicio = $pc - 1;
$inicio = $inicio * $registros_pagina;
#Limitamos a nossa consulta do MySQL para exibir apenas a quantidade máxima configurada mais acima
$resultado = mysql_query("$sql LIMIT $inicio, $registros_pagina");
#Vamos agora consultar a quantidade total de registros
$todos = mysql_query("$sql");
#Armazenamos a quantidade total de registros
$tr = mysql_num_rows($todos);
#Armazenamos o resultado da quantidade total de registros pela quantidade de registros por página
$tp = $tr / $registros_pagina;
#Se não houverem registros a se exibir, é acusado o retorno abaixo
if(mysql_num_rows($resultado) < 1) {
$mensagem = "Nenhum registro foi encontrado!";
}
#Caso contrário é exibido o resultado da consulta
else {
#Exibimos o resultado dos registros encontrados na consulta
while($linha = mysql_fetch_array($resultado)) {
$id = $linha["iditem"];
$coditem = $linha["coditem"];
$nome = $linha["nome"];
$estoqueT = $linha["estoqueT"];
$estoqueM = $linha["estoqueM"];
$precoV = $linha["precoV"];
$precoC = $linha["precoC"];
$valorTV = $linha["valorT"];
$valorTC = $precoC * $estoqueT;
$valorTC = number_format($valorTC, 2,',','.');
$valorTV = number_format($valorTV, 2,',','.');
$precoC = number_format($precoC, 2,',','.');
$precoV = number_format($precoV, 2,',','.');
$nome = mb_strtoupper($nome);
$coditem = mb_strtoupper($coditem);
echo "<tr>
<td width='8%' align='center'>$coditem</td>
<td width='40%' >$nome</td>
<td width='5%' align='center' style='color: red; font-weight:bold;'>$estoqueT</td>
<td width='11%' align='center'>$precoC</td>
<td width='11%' align='center'>$valorTC</td>
<td width='11%' align='center'>$precoV</td>
<td width='11%' align='center'>$valorTV</td>
</tr>";
}
echo "</table><table width='98%'>";
echo "<tr>
<td><br></td>
<tr>";
echo "<tr>
<td align='center'>";
#E por fim montamos os links da paginação
$tp = ceil($tp);
if($pc>1) {
$anterior = $pc - 1;
echo "<a style='text-decoration: none; font-size: 12px; color: gray; font-weight: bold;' href=\"?lista=$anterior\">ANTERIOR </a> ";
}
for($i=$pc-5;$i<$pc;$i++) {
if($i<=0) {
}
else {
echo "<a style='text-decoration: none; font-size: 12px; color: gray; font-weight: bold;' href=\"?lista=$i\">";
if($i=="$pc") {
echo "<b>$i </b>";
}
else {
echo "$i ";
}
echo "</a> ";
}
}
for($i=$pc;$i<=$pc+5;$i++) {
if($i==$tp) {
echo "<a style='text-decoration: none; font-size: 12px; color: gray; font-weight: bold;' href=\"?lista=$i\">";
if($i=="$pc") {
echo "<b>$i </b>";
}
else {
echo "$i ";
}
echo "</a> ";
break;
}
else {
echo "<a style='text-decoration: none; font-size: 12px; color: gray; font-weight: bold;' href=\"?lista=$i\">";
if($i=="$pc") {
echo "<b>$i </b>";
}
else {
echo "$i ";
}
echo "</a> ";
if($i==$pc+5 && $tp>$pc+5) {
echo " ... <a style='text-decoration: none; font-size: 12px; color: gray; font-weight: bold;' href=\"?lista=$tp\">$tp</a>";
}
}
}
if($pc<$tp) {
$proxima = $pc + 1;
echo " <a style='text-decoration: none; font-size: 12px; color: gray; font-weight: bold;' href=\"?lista=$proxima\">PRÓXIMA </a>";
}
}
echo "</td>
</tr>";
?>
<tr>
<td><br><br></td>
</tr>
<tr align="center">
<td colspan="8" >
<?php
if ( isset( $_GET["msg"] ) ){
$msg = $_GET["msg"];
echo "<script> alert('$msg'); </script>";
}
?>
</td>
</tr>
<tr align="center">
<td colspan="8" ><?php echo $mensagem; ?></td>
</tr>
</table>Carregando comentários...