To atras de um script que faz paginação de dados em colunas e linhas, já procurei na net, e nada que funcionasse (queria algo que não fizesse um monte de consultas ao BD, e que fosse fosse possivel filtar dados através de um dropdown)
Bom, consegui algumas coisas que acabei fazendo esse frankstein abaixo, porém a paginação não funciona corretamente
Quando chamo o arquivo, ele não faz a filtragem e traz todos os dados corretamente, bem como a paginação funciona 100%
Porem quando faço a filtragem no dropdown, a primeira pagina vem de forma correta, ou seja exibe apenas os dados filtrados, aparece o nº de registros filtrados e o nº de paginas também
So que quando clico na pagina seguinte, ele simplesmente limpa a filtragem de dados e passa a exibir os dados sem o filtro.
alguém pode me ajudar onde estou errando
<form name="frmBusca" action="<?php echo $_SERVER['PHP_SELF'] ?>?a=search" method="post">
<table width="441" border="0" align="left" cellpadding="2" cellspacing="0">
<tr>
<td width="60" valign="top">Category:</td>
<td width="42"><select name="category" id="category" class="Select">
<?php
$GetCat = mysql_query("SELECT id_cat,cat FROM cat ORDER BY cat ASC") or die(mysql_error());
// display category info in dropdown box
while ($Row = mysql_fetch_object($GetCat)) {
echo ("<option value=\"" . $Row->id_cat . "\">" . $Row->cat . "</option>");
}
?>
</select>
<td width="36" valign="top">Type:</td>
<td width="115"><select name="type" id="type" class="Select">
<?php
$GetType = mysql_query("SELECT id_type,type FROM type ORDER BY type ASC") or die(mysql_error());
// display category info in dropdown box
while ($Row = mysql_fetch_object($GetType)) {
echo ("<option value=\"" . $Row->id_type . "\">" . $Row->type . "</option>");
}
?>
</select>
<input name="search" type="submit" value="Search" /> </tr>
</table>
</form>
<br>
<p>
<?php
//conexao com seu bd
// Verificamos se a ação é de busca
$a = $_GET['a'];
if ($a == "search"){
$category = trim($_POST['category']);
$type = trim($_POST['type']);
}
$sql = "select s.url, s.data, s.thumb, s.descryption, c.cat, t.type from site as s inner join cat as c on s.id_cat=c.id_cat inner join type as t on s.id_type=t.id_type where c.id_cat like '%".$category."%' and t.id_type like '%".$type."%' order by s.id_site desc "; //altere (tabela) para o nome de sua tabela.
$resultado = mysql_query($sql) or die ("Impossible do it!!!");
$pg = $_GET['pg'];
if (!isset($pg))
{
$pg = 1;
}
$lpp = 8; // defina o número de resultados por página.
$total = mysql_num_rows($resultado);
if ($total <= $lpp)
{
$total_paginas = 1;
} else {
$total_paginas = ceil($total/$lpp);
}
$inicio = ($pg - 1) * $lpp;
$final = $inicio + $lpp - 1;
$ponteiro = 0;
$i = "1";
echo "<p>Founded: "."<b>"."$total"."</b>"." records"."</p>";
echo "<p>Show page: "."<b>"."$pg"."</b>"."</p>";
$colunas="4"; // número de colunas desejado.
$total="1";
echo "<table>";
$sql = "select s.url, s.data, s.thumb, s.descryption, c.cat, t.type from site as s inner join cat as c on s.id_cat=c.id_cat inner join type as t on s.id_type=t.id_type where c.id_cat like '%".$category."%' and t.id_type like '%".$type."%' LIMIT $inicio, $lpp"; //altere (tabela) para o nome de sua tabela.
$resultado = mysql_query($sql) or die ("Impossible do it!!!");
while($array_result=mysql_fetch_array($resultado)){
//$cat = $array_result["cat"]; //parâmetro desejado para o resultado.
$cat = $array_result["cat"];
$type = $array_result["type"];
$url = $array_result["url"];
$thumb = $array_result["thumb"];
$descry = $array_result["descryption"];
if($total==1){
echo "<tr>";
}
echo "<td align=center>";
echo "$cat<br>";
echo "<a href= $url><img src= $thumb alt=$descry /></a>";
//echo "<a href= $url; target="_blank"<img src= $thumb;> alt $descry; />"
//echo; // retorna o resultado.
echo "</td>";
if($total==$colunas){
echo "</tr>";
$total=0;
}
$total=$total+1;
}
if(!$total==$colunas){
echo "</tr></table>";
} else {
echo "</table>";
}
?>
<?php
if ($pg == 1) {
echo "<font size=2 color=#000000>";
echo "Previous |";
echo "</font>";
}
else
{
echo "<font size=2 color=#000000>";
echo "<a href=\"1.php?pg=".($pg - 1)."\" targe=\"_self\">Previous</a> |"; // link de sua página.
echo "</font>";
}
$i = 1;
while ($i <= $total_paginas) {
if ($i == $pg)
{
echo "<strong><font size=2 color=#000000>";
echo " <b>|<u>$i</u>|</b> ";
echo "</font></strong>";
}
else
{
echo "<strong><font size=2 color=#000000>";
echo " <a href=\"1.php?pg=".$i."\" target=\"_self\">".$i."</a> "; // link de sua página.
echo "</font></strong>";
}
$i = $i + 1;
}
if ($pg == $total_paginas)
{
echo "<font size=2 color=#000000>";
echo "| Next\n";
echo "</font>";
}
else
{
echo "<font size=2 color=#000000>";
echo "| <a href=\"1.php?pg=".($pg + 1)."\" targe=\"_self\">Next</a>\n"; // link de sua página.
echo "</font>"; }
?>
Pergunta
caphoundy
Galera
To atras de um script que faz paginação de dados em colunas e linhas, já procurei na net, e nada que funcionasse (queria algo que não fizesse um monte de consultas ao BD, e que fosse fosse possivel filtar dados através de um dropdown)
Bom, consegui algumas coisas que acabei fazendo esse frankstein abaixo, porém a paginação não funciona corretamente
Quando chamo o arquivo, ele não faz a filtragem e traz todos os dados corretamente, bem como a paginação funciona 100%
Porem quando faço a filtragem no dropdown, a primeira pagina vem de forma correta, ou seja exibe apenas os dados filtrados, aparece o nº de registros filtrados e o nº de paginas também
So que quando clico na pagina seguinte, ele simplesmente limpa a filtragem de dados e passa a exibir os dados sem o filtro.
alguém pode me ajudar onde estou errando
<form name="frmBusca" action="<?php echo $_SERVER['PHP_SELF'] ?>?a=search" method="post"> <table width="441" border="0" align="left" cellpadding="2" cellspacing="0"> <tr> <td width="60" valign="top">Category:</td> <td width="42"><select name="category" id="category" class="Select"> <?php $GetCat = mysql_query("SELECT id_cat,cat FROM cat ORDER BY cat ASC") or die(mysql_error()); // display category info in dropdown box while ($Row = mysql_fetch_object($GetCat)) { echo ("<option value=\"" . $Row->id_cat . "\">" . $Row->cat . "</option>"); } ?> </select> <td width="36" valign="top">Type:</td> <td width="115"><select name="type" id="type" class="Select"> <?php $GetType = mysql_query("SELECT id_type,type FROM type ORDER BY type ASC") or die(mysql_error()); // display category info in dropdown box while ($Row = mysql_fetch_object($GetType)) { echo ("<option value=\"" . $Row->id_type . "\">" . $Row->type . "</option>"); } ?> </select> <input name="search" type="submit" value="Search" /> </tr> </table> </form> <br> <p> <?php //conexao com seu bd // Verificamos se a ação é de busca $a = $_GET['a']; if ($a == "search"){ $category = trim($_POST['category']); $type = trim($_POST['type']); } $sql = "select s.url, s.data, s.thumb, s.descryption, c.cat, t.type from site as s inner join cat as c on s.id_cat=c.id_cat inner join type as t on s.id_type=t.id_type where c.id_cat like '%".$category."%' and t.id_type like '%".$type."%' order by s.id_site desc "; //altere (tabela) para o nome de sua tabela. $resultado = mysql_query($sql) or die ("Impossible do it!!!"); $pg = $_GET['pg']; if (!isset($pg)) { $pg = 1; } $lpp = 8; // defina o número de resultados por página. $total = mysql_num_rows($resultado); if ($total <= $lpp) { $total_paginas = 1; } else { $total_paginas = ceil($total/$lpp); } $inicio = ($pg - 1) * $lpp; $final = $inicio + $lpp - 1; $ponteiro = 0; $i = "1"; echo "<p>Founded: "."<b>"."$total"."</b>"." records"."</p>"; echo "<p>Show page: "."<b>"."$pg"."</b>"."</p>"; $colunas="4"; // número de colunas desejado. $total="1"; echo "<table>"; $sql = "select s.url, s.data, s.thumb, s.descryption, c.cat, t.type from site as s inner join cat as c on s.id_cat=c.id_cat inner join type as t on s.id_type=t.id_type where c.id_cat like '%".$category."%' and t.id_type like '%".$type."%' LIMIT $inicio, $lpp"; //altere (tabela) para o nome de sua tabela. $resultado = mysql_query($sql) or die ("Impossible do it!!!"); while($array_result=mysql_fetch_array($resultado)){ //$cat = $array_result["cat"]; //parâmetro desejado para o resultado. $cat = $array_result["cat"]; $type = $array_result["type"]; $url = $array_result["url"]; $thumb = $array_result["thumb"]; $descry = $array_result["descryption"]; if($total==1){ echo "<tr>"; } echo "<td align=center>"; echo "$cat<br>"; echo "<a href= $url><img src= $thumb alt=$descry /></a>"; //echo "<a href= $url; target="_blank"<img src= $thumb;> alt $descry; />" //echo; // retorna o resultado. echo "</td>"; if($total==$colunas){ echo "</tr>"; $total=0; } $total=$total+1; } if(!$total==$colunas){ echo "</tr></table>"; } else { echo "</table>"; } ?> <?php if ($pg == 1) { echo "<font size=2 color=#000000>"; echo "Previous |"; echo "</font>"; } else { echo "<font size=2 color=#000000>"; echo "<a href=\"1.php?pg=".($pg - 1)."\" targe=\"_self\">Previous</a> |"; // link de sua página. echo "</font>"; } $i = 1; while ($i <= $total_paginas) { if ($i == $pg) { echo "<strong><font size=2 color=#000000>"; echo " <b>|<u>$i</u>|</b> "; echo "</font></strong>"; } else { echo "<strong><font size=2 color=#000000>"; echo " <a href=\"1.php?pg=".$i."\" target=\"_self\">".$i."</a> "; // link de sua página. echo "</font></strong>"; } $i = $i + 1; } if ($pg == $total_paginas) { echo "<font size=2 color=#000000>"; echo "| Next\n"; echo "</font>"; } else { echo "<font size=2 color=#000000>"; echo "| <a href=\"1.php?pg=".($pg + 1)."\" targe=\"_self\">Next</a>\n"; // link de sua página. echo "</font>"; } ?>Link para o comentário
Compartilhar em outros sites
4 respostass a esta questão
Posts Recomendados
Participe da discussão
Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.