variable does not load in pagination

0

I'm trying to make the pagination search of my site from a search form but I'm not getting the variable that comes via POST to load on the other pages and is not empty. The variable is $ search. How do I proceed so that this variable loads in pagination and is not empty?

Search form:

<form name="Busca" method="post" action="index.php?pg=pesquisa2">
    <label>
        <input type="text" name="busca" placeholder=" O que você procura?" />
    </label>            

    <select id="estados" name="estados" id="form_idade">
        <option value="" selected="selected"> Selecione o estado </option>
        <?php
        $sql = mysql_query("SELECT * FROM estados");

        while($row = mysql_fetch_array($sql)){
            $id = $row['cod_estados'];
            $sigla = $row['sigla'];
            $nome = $row['nome'];
        ?>

            <option value="<?php echo $id ?>">
                <?php echo $nome ?>-<?php echo $sigla ?>
            </option> 

        <?php
        }
        ?>
    </select>
    </label>

    <label>
        <select id="cidades" name="cidades">
            <option value="" selected="selected"> Selecione a cidade</option>                   
        </select>

        <input type="image" src="01-Imagens/pesquisar03_btn.png" name="executar" id="executar" value="Ir" />
</form>  

Paging:

<?php
$busca=$_POST['busca']; 
$anuncioEstado = strip_tags(trim($_POST['estados']));
$anuncioCidade = strip_tags(trim($_POST['cidades']));       
?>


<?php   
if(!empty($_POST['busca']) && ($anuncioEstado == null) &&($anuncioCidade == null)){


    $pag = "$_GET[pag]";
    if($pag >= '1'){
        $pag = $pag;
    }else{
        $pag = '1';
    }

    $maximo = '6'; //RESULTADOS POR PÁGINA
    $inicio = ($pag * $maximo) - $maximo;


    $sql = mysql_query("SELECT * FROM fj_cadastroanuncio WHERE anunciopalavraChave LIKE '%".$busca."%'
                        AND anuncioTipoPlano LIKE '%PN%' AND anuncioStatus = 'completo' ORDER BY RAND() LIMIT ".$inicio.",".$maximo);
    $row = mysql_num_rows($sql);

if ($row > 0){
?>      



<?php

$sql_res = mysql_query("SELECT * FROM fj_cadastroanuncio WHERE anunciopalavraChave LIKE '%".$busca."%' 
                        AND anuncioTipoPlano LIKE '%PN%' AND anuncioStatus = 'completo' ORDER BY RAND()");
$total = mysql_num_rows($sql_res);

$paginas = ceil($total/$maximo);
$links = '6'; 


for ($i = $pag-$links; $i <= $pag-1; $i++){
    if ($i <= 0){
    }else{
        echo"<a href=\"index.php?pg=pesquisa2&amp;pag=$i\">$i</a>&nbsp;&nbsp;&nbsp;";
    }
}echo "$pag &nbsp;&nbsp;&nbsp;";

for($i = $pag +1; $i <= $pag+$links; $i++){
    if($i > $paginas){
    }else{
        echo "<a href=\"index.php?pg=pesquisa2&amp;pag=$i\">$i</a>&nbsp;&nbsp;&nbsp;";
    }
}
?>
    
asked by anonymous 23.09.2016 / 05:42

1 answer

1

I would change $_POST['busca'] to $_REQUEST['busca'] , so that the variable can receive data both by post and get .

You would also begin to submit search data in the pagination link:

index.php?pg=pesquisa2&pag=$i&busca=$busca

I hope I have helped.

    
23.09.2016 / 14:32