Filter and pagination

0

I developed a web page that uses pagination and filter, both made in PHP . This means that after using the filter, and selecting for example page 2, the information will be lost because it will reload all the information.

I've been searching and found the following:

link

link

Is it possible to use something like this with database connection?

As I do not know what to use for sure, it will be necessary to edit tags and title

Current code

filter

  <FORM NAME ="form" METHOD ="POST" >




                   <select name="name" style='width:120px;' id="mySelect" >
                       <option value='' >Ordenar por:</option>
                       <option  value='cod_filme'>Mais recentes</option>
                       <option value='visualizacoes' >Mais vistos</option>
                   </select>



                   <select style='width:70px;' name="pesquisa" id="mySelect" >
                       <?php
                       error_reporting(E_ALL ^ E_DEPRECATED);
                       mysql_connect('127.0.0.1','root','');
                       mysql_select_db('trabalho_pratico');


                       $SQL = "SELECT * FROM ano";
                       $result = mysql_query($SQL);
                       print "<option value='' >Ano:</option>";
                       while ( $db_field = mysql_fetch_assoc($result) ) {
                           print "<option value=" . $db_field['ano'] . ">" . $db_field['ano'] . "</option>";

                       }

                       ?>
                   </select>

                   <select name="categ" style='width:130px;' id="mySelect">
                       <?php
                       error_reporting(E_ALL ^ E_DEPRECATED);
                       mysql_connect('127.0.0.1','root','');
                       mysql_select_db('trabalho_pratico');


                       $SQL = "SELECT * FROM categoria";
                       $result = mysql_query($SQL);
                       print "<option value='' >Categoria:</option>";
                       while ( $db_field = mysql_fetch_assoc($result) ) {
                           print "<option value=" . $db_field['categoria'] . ">" . $db_field['categoria'] . "</option>";

                       }

                       ?>
                   </select>
                   <td>
                       <input type='text' placeholder="Nome" name='procura'>
                   </td>
                   <input style='width:95px;'  type="submit" name="submitfiltro">
               </form>

Displaying filtered content with pagination

 if(($ano!="")&&($matr=="")&&($cat=="")&&($proc=="")){
                   $vari= "SELECT * FROM filme where ano=$ano";
                   $final_query="FROM filme where ano=$ano";
                   error_reporting(E_ALL ^ E_DEPRECATED);
                   mysql_connect('127.0.0.1','root','');
                   mysql_select_db('trabalho_pratico');
                   $maximo = 8;
                   $pagina = (isset($_GET["pagina"])) ? $_GET["pagina"] : null;
                   if($pagina == "") {
                       $pagina = "1";
                   }
                   $inicio = $pagina - 1;
                   $inicio = $maximo * $inicio;
                   $strCount = "SELECT COUNT(*) AS 'num_registros' $final_query";
                   $query = mysql_query($strCount);
                   $row = mysql_fetch_array($query);
                   $total = $row["num_registros"];
                   $SQL =$vari .  ' LIMIT '. $inicio. ' , '.$maximo;
                   $result = mysql_query($SQL);
                   while ( $db_field = mysql_fetch_assoc($result) ) {
                       $img=$db_field['imagem'];
                       echo '<a href="conteudo.php?$op='.$img.'"><img src="' . $img . '"></a>';
                   }
                   $menos = $pagina - 1;
                   $mais = $pagina + 1;

                   $pgs = ceil($total / $maximo);
                   echo "<br>";
                   if($pgs > 1 ) {

                       echo "<br />";

                       // Mostragem de pagina
                       if($menos > 0) {
                           echo "<a href=".$_SERVER['PHP_SELF']."?pagina=$menos>anterior</a>&nbsp; ";
                       }

                       // Listando as paginas
                       for($i=1;$i <= $pgs;$i++) {
                           if($i != $pagina) {
                               echo " <a href='?pagina=".($i)."'>$i</a> | ";
                           } else {
                               echo " <strong>".$i."</strong> | ";
                           }
                       }

                       if($mais <= $pgs) {
                           echo " <a href=".$_SERVER['PHP_SELF']."?pagina=$mais>próxima</a>";
                       }
                   }

Content displayed after filtering

WhenIselectthenextpageinpagination

    
asked by anonymous 22.06.2016 / 14:46

1 answer

1

The idea of paging with filters is that you "save" which filter the user has selected so that when they click on other pages, the filter is not lost.

A practical example

Let's say I have a select containing the following values:

<select>
  <option value="1">Filtro padrão por id</option>
  <option value="2">Filtro por A-Z</option>
  <option value="3">Filtro por Z-A</option>
</select> 

When you click on one of them, the list is sorted with this value.

In pagination, you must also inform the page, the filter that is currently selected.

<ul class="pagination">
  <li><a href="#">Pagina 1 e Filtro código ${De acordo com oq tiver na sessão}</a></li>
  <li><a href="#">Pagina 2 e Filtro código ${De acordo com oq tiver na sessão}</a></li>
  <li><a href="#">Pagina 3 e Filtro código ${De acordo com oq tiver na sessão}</a></li>
  <li><a href="#">Pagina 4 e Filtro código ${De acordo com oq tiver na sessão}</a></li>
  <li><a href="#">Pagina 5 e Filtro código ${De acordo com oq tiver na sessão}</a></li>
</ul>
    
22.06.2016 / 15:33