0
I’m trying to make the search pagination of my site from a search form but I’m not getting the variable that comes via POST to click on the other pages and not be empty. The variable is $search. How do I make this variable click on the 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&pag=$i\">$i</a> ";
}
}echo "$pag ";
for($i = $pag +1; $i <= $pag+$links; $i++){
if($i > $paginas){
}else{
echo "<a href=\"index.php?pg=pesquisa2&pag=$i\">$i</a> ";
}
}
?>
in my view, order by Rand does not go much with paging, and as for the search problem to come blank, all form fields should be recreated as hidden fields, so they go to the next pages...
– Jader A. Wagner
I forgot to mention, your script is vulnerable, I advise you to treat the variables before including them in the query, and review the use of mysql_* that are obsolete...
– Jader A. Wagner