Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

scooler

Paginação e query sting

Recommended Posts

Falae galera!

 

Estou usando query string na index mas quando faço a paginacao de uma busca no arquivo busca.php os links PROXIMO e ANTERIOR sao direcionados para a index

 

Obs.: Estou usando aquele esquema de paginacao da area de codigos

 

A query esta assim, mas sera que eu devo usar um outro esquema para a query?

 

if (empty($df)) {

include ("principal.php");

} else {

include ("$df.php");

}

 

Eu tentei fazer algumas alteracoes mas nao deu certo. Nos links de paginacao eu coloquei um caminho diferente, tipo:

 

<a href='$PHP_SELF?df=busca&pagina=$anterior&trecho=$trecho'>Anterior</a>

ao inves de

<a href=paginacao.php?pagina=$anterior>Anterior</a>

 

e alguns links da paginacao nao ficaram como estavam antes, por exemplo, na primeira pagina o numero de resultados 1 era assim [1] depois nao ficou mais desta forma, entre outros erros.

 

ja tentei varias formas de link p/ a paginacao mas acho que o erro esta na query. Voces poderiam me ajudar nesta duvida?

 

Valeu!

Compartilhar este post


Link para o post
Compartilhar em outros sites

O codigo é este:

 

     <?   $trecho = (htmlspecialchars($trecho));      if ($trecho == "") {          echo "<table width=100% border=0 cellspacing=0 cellpadding=0>                <tr>                 <td valign=top><img src=imagens/banner_busca.gif width=475 height=44></td>                </tr>                </table>                <table width=100% border=0 cellspacing=0 cellpadding=0>                <tr>                 <td><img src=imagens/spacer.gif width=1 height=1></td>                </tr>                </table>    <table width=100%>    <tr valign=top>     <td width=7%><img src=imagens/spacer.gif width=1 height=1></td>                <td width=50%><a href='index.php'><font size=1 face=verdana color=666666onmouseover=\"this.style.color='#C0C0C0'\" onmouseout=\"this.style.color='#666666'\">Index</a></font><font face=arial size=1 color=#666666>  ></font><font face=verdana size=1 color=#666666> <b>Busca</b></font></td>                <td width=43% align=right><a href=javascript:history.back(-1);><font size=1 face=verdanacolor=666666 onmouseover=\"this.style.color='#C0C0C0'\" onmouseout=\"this.style.color='#666666'\">Voltar</a>                 </font></td>                </tr>    </table>          <table width=100% border=0 cellspacing=0 cellpadding=0>                <tr>                 <td width=97% valign=top> <table width=100% border=0 cellpadding=0 cellspacing=0>                </table>                <table width=100% border=0 cellpadding=0 cellspacing=0>                <tr>                 <td height=1><img src=imagens/spacer.gif width=1 height=1></td>                </tr>                </table>                <table width=100% border=0 cellpadding=0 cellspacing=0>                <tr>                 <td background=imagens/tracos_litle.gif><img src=imagens/spacer.gif width=1 height=1></td>                </tr>                </table>                <table width=100% border=0 cellpadding=0 cellspacing=0>                <tr>                 <td height=8><img src=imagens/spacer.gif width=1 height=1></td>                </tr>                </table>                </td>                <td width=3%> </td>                </tr>                </table>                <table width=100%>                <tr>                <td><font face=verdana size=2 color=#red><b>Resultado(s) da busca:</b></font></td>                </tr>                </table>                <table width=100% border=0 cellpadding=0 cellspacing=0 background=img/balls.gif>                <tr width=100%><td width=100%><img src=imagens/spacer.gif border=0 width=1 height=1></td></tr>                </table>                <table height=25 width=100% border=0 callpadding=0 cellspacing=0 bgcolor=#F9F9F9>                <tr><td valign=middle>                <font face='verdana' size='1' color='#000000'>  Foram encontrada(s) <b>0</b>ocorrência(s) para \"<b>$trecho</b>\".</tr>                   <table width=100% border=0 cellpadding=0 cellspacing=0 background=img/balls.gif>                <tr><td><img src=imagens/spacer.gif border=0 width=1 height=1></td></tr>                </table><br>                <table width=100% border=0 cellpadding=0 cellspacing=0>                <tr width=100%><td width=100%><font face=verdana size=1 color=#000000>                                              <b>Dicas para facilitar a sua busca:</b><br><br>                                               - Verifique se a palavra foi digitada corretamente<br>                                              - Veja se o conteúdo consta no site<br>                                              - Confira se algum caracter foi digitado</font></td></tr>                </table>"; }    else {      require ("conexao.php");    $busca = "SELECT * FROM pesquisa WHERE (titulo LIKE '%$trecho%') or (texto LIKE '%$trecho%')";    $todos = mysql_query($busca);    $tr = mysql_num_rows($todos);        if ($tr == 0) {           echo "<table width=100% border=0 cellspacing=0 cellpadding=0>                <tr>                 <td valign=top><img src=imagens/banner_busca.gif width=475 height=44></td>                </tr>                </table>                <table width=100% border=0 cellspacing=0 cellpadding=0>                <tr>                 <td><img src=imagens/spacer.gif width=1 height=1></td>                </tr>                </table>    <table width=100%>    <tr valign=top>     <td width=7%><img src=imagens/spacer.gif width=1 height=1></td>                <td width=50%><a href=index.php><font size=1 face=verdana color=666666 onmouseover=\"this.style.color='#C0C0C0'\" onmouseout=\"this.style.color='#666666'\">Index</a></font><font face=arial size=1 color=#666666>  ></font><font face=verdana size=1 color=#666666> <b>Busca</b></font></td>                <td width=43% align=right><a href=javascript:history.back(-1);><font size=1 face=verdana color=666666 onmouseover=\"this.style.color='#C0C0C0'\" onmouseout=\"this.style.color='#666666'\">Voltar</a>                 </font></td>                </tr>    </table>          <table width=100% border=0 cellspacing=0 cellpadding=0>                <tr>                 <td width=97% valign=top> <table width=100% border=0 cellpadding=0 cellspacing=0>                </table>                <table width=100% border=0 cellpadding=0 cellspacing=0>                <tr>                 <td height=1><img src=imagens/spacer.gif width=1 height=1></td>                </tr>                </table>                <table width=100% border=0 cellpadding=0 cellspacing=0>                <tr>                 <td background=imagens/tracos_litle.gif><img src=imagens/spacer.gif width=1 height=1></td>                </tr>                </table>                <table width=100% border=0 cellpadding=0 cellspacing=0>                <tr>                 <td height=8><img src=imagens/spacer.gif width=1 height=1></td>                </tr>                </table>                </td>                <td width=3%> </td>                </tr>                </table>                <table width=100%>                <tr>                <td><font face=verdana size=2 color=#000000><b>Resultado(s) da busca:</b></font></td>                </tr>                </table>                <table width=100% border=0 cellpadding=0 cellspacing=0 background=img/balls.gif>                <tr width=100%><td width=100%><img src=imagens/spacer.gif border=0 width=1 height=1></td></tr>                </table>                <table height=25 width=100% border=0 callpadding=0 cellspacing=0 bgcolor=#F9F9F9>                <tr><td valign=middle>                <font face='verdana' size='1' color='#000000'>  Foram encontrada(s) <b>$totProd</b> ocorrência(s) para \"<b>$trecho</b>\".</tr>                   <table width=100% border=0 cellpadding=0 cellspacing=0 background=img/balls.gif>                <tr><td><img src=imagens/spacer.gif border=0 width=1 height=1></td></tr>                </table><br>                <table width=100% border=0 cellpadding=0 cellspacing=0>                <tr width=100%><td width=100%><font face=verdana size=1 color=#000000>                                              <b>Dicas para facilitar a sua busca:</b><br><br>                                               - Verifique se a palavra foi digitada corretamente<br>                                              - Veja se o conteúdo consta no site<br>                                              - Confira se algum caracter foi digitado</font></td></tr>                </table>";             }            elseif ($tr > 0) {          echo "<table width=100% border=0 cellspacing=0 cellpadding=0>                <tr>                 <td valign=top><img src=imagens/banner_busca.gif width=475 height=44></td>                </tr>                </table>                <table width=100% border=0 cellspacing=0 cellpadding=0>                <tr>                 <td><img src=imagens/spacer.gif width=1 height=1></td>                </tr>                </table>    <table width=100%>    <tr valign=top>     <td width=7%><img src=imagens/spacer.gif width=1 height=1></td>                <td width=50%><a href=index.php><font size=1 face=verdana color=666666 onmouseover=\"this.style.color='#C0C0C0'\" onmouseout=\"this.style.color='#666666'\">Index</a></font><font face=arial size=1 color=#666666>  ></font><font face=verdana size=1 color=#666666> <b>Busca</b></font></td>                <td width=43% align=right><a href=javascript:history.back(-1);><font size=1 face=verdana color=666666 onmouseover=\"this.style.color='#C0C0C0'\" onmouseout=\"this.style.color='#666666'\">Voltar</a>                 </font></td>                </tr>    </table>          <table width=100% border=0 cellspacing=0 cellpadding=0>                <tr>                 <td width=97% valign=top> <table width=100% border=0 cellpadding=0 cellspacing=0>                </table>                <table width=100% border=0 cellpadding=0 cellspacing=0>                <tr>                 <td height=1><img src=imagens/spacer.gif width=1 height=1></td>                </tr>                </table>                <table width=100% border=0 cellpadding=0 cellspacing=0>                <tr>                 <td background=imagens/tracos_litle.gif><img src=imagens/spacer.gif width=1 height=1></td>                </tr>                </table>                <table width=100% border=0 cellpadding=0 cellspacing=0>                <tr>                 <td height=8><img src=imagens/spacer.gif width=1 height=1></td>                </tr>                </table>                </td>                <td width=3%> </td>                </tr>                </table>                <table width=100% border=0 cellpadding=0 cellspacing=0 background=img/balls.gif>                <tr width=100%><td width=100%><img src=imagens/spacer.gif border=0 width=1 height=1></td></tr>                </table>                <table height=25 width=100% border=0 callpadding=0 cellspacing=0 bgcolor=#F9F9F9>                <tr><td valign=middle>                <font face='verdana' size='1' color='#000000'>  Foram encontrada(s) <b>$tr</b> ocorrência(s) para \"<b>$trecho</b>\".</tr>                   <table width=100% border=0 cellpadding=0 cellspacing=0 background=img/balls.gif>                <tr><td><img src=imagens/spacer.gif border=0 width=1 height=1></td></tr>                </table><br>";        $total_registro = "3";    if(isset($pagina)) {	$pc = $pagina;} else {	$pc = "1";}$inicio = $pc - 1;$inicio = $inicio * $total_registro;$limite = mysql_query("$busca LIMIT $inicio, $total_registro");$todos = mysql_query("$busca");$tr = mysql_num_rows($todos);$tp = $tr / $total_registro;//criando a visualizacaowhile ($dados = mysql_fetch_array($limite)) {echo "<table height=0 valign=top width=100% border=0 cellspacing=0 cellpadding=0>";echo "<tr width=100% align=left valign=top>";echo "<td width=75%><font face=verdana size=1 color=#000000><b>".$dados['titulo']."</b></font><br>";echo "<font face=verdana size=1 color=#000000>".$dados['texto']."</font><br>";echo "<font face=verdana size=1 color=#000000><a href=$dados[endereco] target=_blank><i>".$dados['endereco']."</i></a></font><br>";echo "</tr>";echo "</table>      <table width=100% border=0 cellspacing=0 cellpadding=0>      <tr>       <td height=26 align=center valign=middle><font color=#999999 size=1 face=verdana>············································································································</font></td>      </tr>      </table>";}//criando os botoes$anterior = $pc-1;$proximo = $pc + 1;echo "<center>";if ($pc > 1) {	echo "<a href='$PHP_SELF?df=busca&pagina=$anterior&trecho=$trecho'><font face=arial size=1><<</font><font face=verdana size=1> Anterior  </font></a>"; }for($c = 1; $c <= $tp; $c ++) {	if ($pagina==$c) {   echo "<font face=verdana size=1><b> [$c] </b></font>";   	} else {	  echo "<a href='$PHP_SELF?df=busca&pagina=$c&trecho=$trecho'><font face=verdana size=1> $c </font></a>";	}}    if ($pc < $tp) {	echo "<a href='$PHP_SELF?df=busca&pagina=$proximo&trecho=$trecho'><font face=verdana size=1>  Próximo </font><font face=arial size=1>>></font></a>";}echo "</center>";}}?>

Valew!

Compartilhar este post


Link para o post
Compartilhar em outros sites

Nessa parte:

$inicio = $pc - 1;

$inicio = $inicio * $total_registro;

$limite = mysql_query("$busca LIMIT $inicio, $total_registro");

$todos = mysql_query("$busca");

$tr = mysql_num_rows($todos);

$tp = $tr / $total_registro;

Coloca isso:

$inicio2 = $pc - 1;

$inicio = $inicio2 * $total_registro;

$fim = $inicio+$total_registro;

$limite = mysql_query("$busca LIMIT $inicio, $fim");

$todos = mysql_query("$busca");

$tr = mysql_num_rows($todos);

$tp = $tr / $total_registro;

E você não colocou tudo o que tinha no script que eu passei, falta algumas coisas, olha lá. Imagem Postada

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.