• 0
Sign in to follow this  
crazySerk

Paginação em minha busca!

Question

Galera, estou precisando da ajuda dos Sr's novamente...

Estive pensando atualmente o meu "sisteminha" está tranquilo, poucas informações mas futuramente vai se tornar grande e com isso o meu campo de "BUSCA" com certeza ficará extensa, para evitar isso, gostaria de adicionar uma forma de paginar minha busca procurei no google porem as que encontrei não consegui adicionar em meu site, então recorri até vocês.

Bom o meu script de busca está abaixo:

<?php include("conexao/config.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Pesquisar</title>
<style type="text/css">
<!--

.style5 {font-family: Tahoma; font-size: 12px; font-weight: bold; }
.style7 {font-size: 12px}
.style10 {font-size: 12px; font-weight: bold; }
.style17 {font-family: Tahoma; font-size: 12px; font-weight: bold; color: #FFFFFF; }
.style18 {
    font-size: 11px;
    font-family: Tahoma;
    font-weight: bold;
    color: #FF0000;
}
.style21 {font-weight: bold; font-family: Tahoma;}
.style23 {color: #000000}
.style24 {
    font-size: 11px;
    color: #000000;
}
.style25 {font-size: 11px}
.style29 {font-family: Tahoma; font-size: 12px; font-weight: bold; color: #000000; }
-->
</style>
<script type="text/javascript" src="scripts/mascara_dados.js"  charset="utf-8">
</script>
<script language="JavaScript">
function abrir(URL) {

  var width = 810;
  var height = 500;

  var left = 130;
  var top = 99;

  window.open(URL,'janela', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=yes, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');

}
</script>
</head>
<?
if($contagem != 1) {
    session_destroy();
    include("login.php");
    }else{
?>
<body>
<table width="792" height="139" border="1" align="center" bordercolor="#000000">
  <tr>
    <td width="714">
      <form id="rm_presquisa" name="rm_presquisa" method="post" action="?page=pesquisar_proposta">
        <span class="style5">Digite o NOME do seu Cliente
        <label></label>
        :
        <label>        </label>
        </span>
        <span class="style10">
        <label>        </label>
        </span><span class="style7"><label></label>
        </span>
        <label>
        <input name="cliente_nome" type="text" id="cliente_nome" size="35" maxlength="14" />
        </label>
        <label>
        <input type="submit" name="pesquisar" id="pesquisar" value="Pesquisar" />
        </label>
      </form>
            <table width="777" height="67" border="1" align="center" bordercolor="#000000">
        <tr>
          <td width="74"><div align="center" class="style23 style25"><span class="style21">N&deg; Proposta</span></div></td>
          <td width="220"><div align="center" class="style23 style25"><span class="style21">Cliente</span></div></td>
          <td width="95"><div align="center" class="style23 style25"><span class="style21">Status</span></div></td>
          <td width="199"><div align="center" class="style17 style23 style25">
            <div align="center">OBS Proposta</div>
          </div>            <div align="center" class="style23 style25"></div></td>
          <td width="77"><div align="center" class="style24"><span class="style21">Anexar Docs</span></div></td>
          <td width="51"><div align="center"><span class="style17 style23 style25">Editar</span></div></td>
        </tr>
        <?php
        include ("conexao/config.php");
        if ($_POST["pesquisar"]){
             //$pesquisar = "";
        //}    else {
            $vendedor = $_SESSION["usuario"];
            $pesquisar = $_POST["cliente_nome"];
            $sql_pesquisa = "SELECT * FROM propostas_digitadas WHERE cliente_nome LIKE '".$pesquisar."%' AND vendedor = '$vendedor' ORDER BY cliente_nome";
            $result = mysql_query($sql_pesquisa); 
    

                while($registro = mysql_fetch_array($result))
                {
        ?>
        <tr>
          <td height="45"><div align="center"><span class="style29"><? echo $registro["cod_proposta"]; ?></span></div></td>
          <td><span class="style29"><? echo $registro["cliente_nome"]; ?></span></td>
          <td><div align="center" class="style23">
            <? if($registro["status_dig"] == "0")
          {
          echo "<img src='images/st_enviado.png' alt='Enviado' width='34' height='30' />";
          } 
              else if ($registro["status_dig"]==1){ 
                    echo "<img src='images/st_analisando.png' alt='Analisando' width='34' height='30' />";
         } else if ($registro["status_dig"]==2){ 
                   echo "<img src='images/st_pendente.png' alt='Pendente' width='34' height='30' />";
        } else if ($registro["status_dig"]==3){ 
              echo "<img src='images/st_aprovado.png' alt='Aprovado' width='34' height='30' />";
         } else if ($registro["status_dig"]==4){ 
             echo "<img src='images/st_reprovado.png' alt='Reprovado' width='34' height='30' />";
             }
                    ?>
         </div></td>
          <td><div align="center"><span class="style18"><? echo $registro["obs_proposta"]; ?></span></div>            <div align="center"></div></td>
          <td><div align="center"><a href="java script:abrir('anexar_doc.php?cod_proposta=<? echo $registro["cod_proposta"]; ?>');"><img src="images/scanner.png" alt="Anexar Documentos" width="40" height="40" /></a></div></td>
          <td><div align="center"><a href="java script:abrir('editar_pessoafisica.php?cod_proposta=<? echo $registro["cod_proposta"]; ?>');"><img src="images/editar.png" width="40" height="40" alt="Editar Proposta" /></a></div></td>
        </tr>
        <?
            }
        }
        ?>
      </table>

    </td>
  </tr>
</table>
<br />
<table width="100" border="0" align="left">
  <tr>
    <td colspan="2"><div align="left" class="style29">
      <div align="center">Legenda</div>
    </div></td>
  </tr>
  <tr>
    <td width="43"><img src="images/st_enviado.png" alt="Enviado" width="34" height="30" /></td>
    <td width="47"><span class="style5 style23">Enviado</span></td>
  </tr>
  <tr>
    <td><img src="images/st_analisando.png" alt="Analisando" width="34" height="30" /></td>
    <td><span class="style5 style23">Analisando</span></td>
  </tr>
  <tr>
    <td><img src="images/st_pendente.png" alt="Pendente" width="34" height="30" /></td>
    <td><span class="style5 style23">Pendente</span></td>
  </tr>
  <tr>
    <td><img src="images/st_reprovado.png" alt="Reprovado" width="34" height="30" /></td>
    <td><span class="style5 style23">Reprovado</span></td>
  </tr>
  <tr>
    <td><img src="images/st_aprovado.png" alt="Aprovado" width="34" height="30" /></td>
    <td><span class="style5 style23">Aprovado</span></td>
  </tr>
</table>
<br />
</body>
<?
}
?>
</html>

AGRADEÇO A TODOS :)

Share this post


Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Veja se funciona:

Crie uma página chamada "paginacao.php" e dentro dele coloque o código abaixo:

<?php
function paginar($pag_referencia, $pagina, $sql){

global $result, $links, $linkss, $inicio; 

$tamanho_pagina = 10;

if (!$pagina){ 
$pagina = 1; 
}else{ 
$pagina = $pagina;
} 

$mat = $pagina - 1;
$inicio = $mat * $tamanho_pagina; 
$rs = mysql_query($sql) or die("Erro: 0000 - Arquivo: paginacao/index.php" . mysql_query()); 

$ssql = " ".$sql." limit " . $inicio . "," . $tamanho_pagina; 
$result = mysql_query($ssql) or die(" <br> Erro: paginacao - 001" . mysql_error()); 

$num_total_registros = mysql_num_rows($rs); 

$total_paginas = ceil($num_total_registros / $tamanho_pagina); 

$volta = $pagina - 1;
$proxima = $pagina + 1;

$linkss .= "<center><b>Total de registros encontrados: <font color=#FF0000>" .$num_total_registros. "</font></b></center>";
$links .= "<form name=\"form1\">";
$links .= "Ir para a página: <select name=\"menu1\" onchange=\"MM_jumpMenu('parent',this,0)\" style=\"font-size:11px; font-family:verdana; background-color: #EFEFEF\">";
$links .= "<option>---</option>";

for ($i = 0; $i < $total_paginas; $i++){ 
$pag = $i + 1; 
$links .= "<option value=\"".$pag_referencia."&pagina=" . $pag . "\">" .$pag. "</option>";
} 

$links .= "</select><br>";

if($volta > 0){ 
$links .= "<a href='".$pag_referencia."&pagina=" . $volta . "'><< Voltar</a> "; 
}

if($pagina < $total_paginas) {
$links .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='".$pag_referencia."&pagina=" .$proxima. "'>Próxima >></a>"; 
} 
$links .= "<br><b>Página <font color=brown size=2 face='verdana, helvetica, arial'><b>" .$pagina. "</b></font> de " .$total_paginas. "</b>";
$links .= "</form>";
}
?>
Depois na página que deseja implantar a paginação, coloque dessa forma:
include("paginacao.php");

$sql = "SELECT * FROM sua_tabela";
paginar("suapagina.php?",$_REQUEST["pagina"], $sql);

while($mtProd = mysql_fetch_object($Res)){

//seus resultados

}
<br />
<font size="1" face="Verdana, Helvetica, Arial">
<b><?=$links;?></b>
</font>

Abs.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this