0
I have the code below and wanted to add the class disabled
when the user is on the page he clicked on. For example: if the user clicks on page 3 the link on page 3 would have the class disabled
so that it is not possible to click it.
Se for a página inicial da consulta, a variável $pag será nula
if(!$pag) {
$pc = "1";
}
Caso contrário, declaramos o valor atual da variável $pag
else {
$pc = $pag;
}
#Armazenamos a quantidade total de registros
$todos = $totalreg->num_rows;
Armazenamos o resultado da quantidade total de registros pela quantidade de registros por página
$tp = $todos / $registros_pagina;
E por fim montamos os links da paginação
$tp = ceil($tp);
if($pc>1) {
$anterior = $pc - 1;
echo '<li><a href="?pag='.$anterior.'" title="Anterior"><i class="fas fa-angle-left"></i></a></li>';
}
for($i=$pc-5;$i<$pc;$i++) {
if($i<=0) {
}
else {
echo '<li><a href="?pag='.$i.'">';
if($i==$pc) {
echo $i;
}
else {
echo $i;
}
echo '</a></li> ';
}
}
for($i=$pc;$i<=$pc+5;$i++) {
if($i==$tp) {
echo '<li><a href="?pag='.$i.'">';
if($i==$pc) {
echo $i;
}
else {
echo $i;
}
echo '</a></li> ';
break;
}
else {
echo '<li><a href="?pag='.$i.'">';
if($i==$pc) {
echo $i;
}
else {
echo $i;
}
echo '</a></li> ';
if($i==$pc+5 && $tp>$pc+5) {
echo ' ... <li><a href="?pag='.$tp.'">'.$tp.'</a></li>';
}
}
}
if($pc<$tp) {
$proxima = $pc + 1;
echo '<li><a href="?pag='.$proxima.'" title="Próxima"><i class="fas fa-angle-right"></i></a></li>';
}
Hello Andrei, it didn’t work, it didn’t insert the class. I think it had to be a query based on the parameter "pag=i" because it would put it in the right place
– Frederico Moreira
@Fredericomoreira sorry, I used the wrong for the view.
– Andrei Coelho
I tried at all. and did not give kkkk. I switched all for in part $i==$pc for $i==$pag and it worked
– Frederico Moreira
@Fredericomoreira try now.
– Andrei Coelho
@Fredericomoreira on the second loop
– Andrei Coelho
@Fredericomoreira has some redundancies in this
for
that I will try to help you correct.– Andrei Coelho
what I could improve on this
for
– Frederico Moreira
Let’s go continue this discussion in chat.
– Andrei Coelho
I did that and really wiped the code. Thank you
– Frederico Moreira
Cool @Fredericomoreira was happy to help! Hug!
– Andrei Coelho