0
I developed a web page that uses paging and filter, both made in PHP
. What makes after using the filter, and select for example page 2, the information will be lost because it will reload all the information.
I’ve been researching and found the following:
http://plnkr.co/edit/Q26WPjLqcOtS8p0mGF6b?p=preview
http://plnkr.co/edit/Wtkv71LIqUR4OhzhgpqL?p=preview
Is it possible to use something like this with database connection ?
Since I don’t 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>
Display of filtered content with paging
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> ";
}
// 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
When I select the next page in the pagination
Explain, what do you really want to do? You need to send the filter information to another page?
– Fleuquer Lima
not what I have is a page where appear news and this page has pagination, the problem is that when putting the filter which is also in php the information when switching to page 2 is lost
– saimita
page 2 you say, is the second page of pagination? Or another page?
– Fleuquer Lima
Yes you can, use SQL from LIMIT (Read the tutorial: http://www.w3schools.com/sql/sql_top.asp) to work it and do the result php. Example:
SELECT * FROM CADASTRO LIMIT 0 , 20
0 is start, 20 is line... next to him 21, 20 and next 41, 20.– KingRider