Clicking on the page always calls the first div

Asked

Viewed 49 times

0

I have two section on the same page. Inside each page section have a div, but when I click on the page of the second div always returns me to the first div.

code:

<?php
require("conexao.php");

$itens_por_pagina = 10;

$itens_por_pagina1 = 10;

// pegar a pagina atual
$pagina = intval($_GET['pagina']);
if (!$pagina) {
$pc = "0";
} else {
$pc = $pagina;
}
$inicio = $pc - 0;
$inicio = $inicio * $itens_por_pagina;

$pagina1 = intval($_GET['pagina1']);
if (!$pagina1) {
$pc1 = "0";
} else {
$pc1 = $pagina1;
}
$inicio1 = $pc1 - 0;
$inicio1 = $inicio1 * $itens_por_pagina1;

$query = "SELECT Id, De, Assunto, Conteudo, Prioridade, TIME_FORMAT(Recebido,'%h:%i') AS Hora, DATE(Recebido) AS Data,
Email, Tipo, raddb.Alertas.Para, Status FROM raddb.Alertas LEFT OUTER JOIN raddb.ValAlertas
ON raddb.ValAlertas.IdSMS = raddb.Alertas.Id AND raddb.ValAlertas.Para = raddb.Alertas.Para
WHERE raddb.Alertas.Para = '$colaborador' 
ORDER BY Recebido Desc LIMIT $inicio, $itens_por_pagina";

$query1 = "SELECT Id, De, Assunto, Conteudo, Prioridade, TIME_FORMAT(Recebido,'%h:%i') AS Hora, DATE(Recebido) AS Data,
 Email, Tipo, raddb.Alertas.Para, Status FROM raddb.Alertas LEFT OUTER JOIN raddb.ValAlertas
ON raddb.ValAlertas.IdSMS = raddb.Alertas.Id AND raddb.ValAlertas.Para = raddb.Alertas.Para
WHERE Tipo = 'Geral' AND raddb.Alertas.Para = '$colaborador'  ORDER BY Recebido Desc LIMIT $inicio1, $itens_por_pagina1";

$result = $conn->query($query) or die($conn->error);
$result1 = $conn->query($query1) or die($conn->error);

$produto = $result->fetch_assoc();
$produto1 = $result1->fetch_assoc();

$num = $result->num_rows;
$num1 = $result1->num_rows;

$num_total = $conn->query("SELECT Id, De, Assunto, Conteudo, Prioridade, TIME_FORMAT(Recebido,'%h:%i') AS Hora, DATE(Recebido) AS Data,
Email, Tipo, raddb.Alertas.Para, Status FROM raddb.Alertas LEFT OUTER JOIN raddb.ValAlertas
ON raddb.ValAlertas.IdSMS = raddb.Alertas.Id AND raddb.ValAlertas.Para = raddb.Alertas.Para
WHERE raddb.Alertas.Para = '$colaborador' 
ORDER BY Recebido Desc")->num_rows;

$num_total1 = $conn->query("SELECT Id, De, Assunto, Conteudo, Prioridade, TIME_FORMAT(Recebido,'%h:%i') AS Hora, DATE(Recebido) AS Data,
 Email, Tipo, raddb.Alertas.Para, Status FROM raddb.Alertas LEFT OUTER JOIN raddb.ValAlertas
ON raddb.ValAlertas.IdSMS = raddb.Alertas.Id AND raddb.ValAlertas.Para = raddb.Alertas.Para
WHERE Tipo = 'Geral' AND raddb.Alertas.Para = '$colaborador'  ORDER BY Recebido Desc")->num_rows;

$num_paginas = ceil($num_total/$itens_por_pagina);

$num_paginas1 = ceil($num_total1/$itens_por_pagina1);

Now the section and the div within the section:

<section id="s1">
<div id="minhaDiv"> 
<div class="col-lg-4">
                <h1>Alerta Recebido</h1>
<?php if($num > 0){ ?> 
    <table class="table table-hover table-striped">  
        <tr> 
            <th width="20%" style="text-align:center;">De</th>
            <th width="60%" style="text-align:center;">Assunto</th>
            <th width="10%" style="text-align:center;">Prioridade</th>
            <th width="10%" style="text-align:center;">Recebido</th>                
        </tr>
        <tr>
    <?php  

        do{

         if($nomede != $produto["De"]){
    ?>  
        <th width="10%" colspan=4>Recebido: <?php echo $produto["Data"]; ?></th>
    <?php
        $nomede = $produto["De"];
        }
   ?>
        </tr>       
        <tr>  
        <td ><?php echo $produto["De"]; ?></td>
        <td class="td-info view_data apagar" id="<?php echo $produto["Id"]; ?>,<?php echo $produto["Para"]; ?>" data-toggle="modal" href="#dataModal" width="20%" <?php echo $produto["Status"] != '0'?' style="font-weight:bold; font-size: 90%" ':' style="font-weight:normal; font-size: 90%" '?>><?php echo $produto["Assunto"]; ?></td>  
        <td><?php echo $produto["Prioridade"]; ?></td> 
        <td><?php echo $produto["Hora"]; ?></td>
        </tr>

<?php } while($produto = $result->fetch_assoc()); ?>
    </table>
<nav>
<ul class="pagination">
<li>
<a href="?pagina=0" aria-label="Previous">
<span aria-hidden="true">&laquo;</span>
</a>
</li>
<?php 
for($i=0;$i<$num_paginas;$i++){
$estilo = "";
if($pc == $i)
$estilo = "class=\"active\"";
?>
<li <?php echo $estilo; ?> ><a href="?pagina=<?php echo $i; ?>"><?php echo $i+1; ?></a></li>
<?php } ?>
<li>
<a href="?pagina=<?php echo $num_paginas-1; ?>" aria-label="Next">
<span aria-hidden="true">&raquo;</span>
</a>
</li>
</ul>
</nav>
<?php } ?>
</div>  
</div>
</section>

<section id="s2">
<div id="minhaDiv1" style="display:none">
<div class="col-lg-4">
                <h1>Alerta Geral</h1>
<?php if($num1 > 0){ ?> 
    <table class="table table-hover table-striped">  
        <tr> 
            <th width="20%" style="text-align:center; font-size: 90%;">De</th>
            <th width="60%" style="text-align:center; font-size: 90%;">Assunto</th>
            <th width="10%" style="text-align:center; font-size: 90%;">Prioridade</th>
            <th width="10%" style="text-align:center; font-size: 90%;">Recebido</th>                
        </tr>
        <tr>
    <?php  
        do{

         if($nomede != $produto1["De"]){
    ?>  
        <th style="font-size: 90%;" width="10%" colspan=4>Recebido: <?php echo $produto1["Data"]; ?></th>
    <?php
        $nomede = $produto1["De"];
        }
   ?>
        </tr>   
        <tr>  
            <td style="font-size: 90%;"><?php echo $produto1["De"]; ?></td> 
            <td class="td-info view_data1 apagar" id="<?php echo $produto1["Id"]; ?>,<?php echo $produto1["Para"]; ?>" data-toggle="modal" href="#dataModal1" width="20%" <?php echo $produto1["Status"] != '0'?' style="font-weight:bold; font-size: 90%" ':' style="font-weight:normal; font-size: 90%" '?>><?php echo $produto1["Assunto"]; ?></td>  
            <td style="font-size: 90%;"><?php echo $produto1["Prioridade"]; ?></td> 
            <td style="font-size: 90%;"><?php echo $produto1["Hora"]; ?></td>
        </tr>

<?php } while($produto1 = $result1->fetch_assoc()); ?>
    </table> 
<nav>
<ul class="pagination">
<li>
<a href="?pagina1=0" aria-label="Previous">
<span aria-hidden="true">&laquo;</span>
</a>
</li>
<?php 
for($i=0;$i<$num_paginas1;$i++){
$estilo = "";
if($pc1 == $i)
$estilo = "class=\"active\"";
?>
<li <?php echo $estilo; ?> ><a href="?pagina1=<?php echo $i; ?>"><?php echo $i+1; ?></a></li>
<?php } ?>
<li>
<a href="?pagina1=<?php echo $num_paginas1-1; ?>" aria-label="Next">
<span aria-hidden="true">&raquo;</span>
</a>
</li>
</ul>
</nav>
<?php } ?>
</div>
</div>      
</section>

The problem will be on the way where I do Next or Previous within each div.The problem is always updating the page when changing pages, but I can’t fix it

I just forgot to mention one thing, I change div with this menu, that’s why every time I change pages updates the page?

<div class="menu2">
  <nav class="navbar navbar-default" style="background-color: #d3d3d3">
  <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-11" aria-expanded="false" style="float: left">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
    </div>
    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="col-lg-4">
                <h1>Alertas</h1>
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-11" style="float: left">
      <ul class="nav navbar-nav" style="background-color: #143b78">
          <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown">
              Caixa de entrada<span class="caret"></span></a>
            <ul class="dropdown-menu">
              <li><a href="#s1" class="btn-show" data-element="#minhaDiv">Recebidas</a></li>
              <li><a href="#s2" class="btn-show" data-element="#minhaDiv1">Geral</a></li>
            </ul>
          </li>
      </ul>
    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>
</div>
  • Here <li><a href="? page=<? php echo $i; ? >"><? php echo $i+1; ? ></a></li>, apparently the correct numbering appears due to $i+1, and in "? page="no count+1, wouldn’t that be it?

1 answer

0

Alters:

<li <?php echo $estilo; ?> ><a href="?pagina=<?php echo $i; ?>"><?php echo $i+1; ?></a></li>

To:

<li <?php echo $estilo; ?> ><a href="?pagina=<?php echo $i+1; ?>"><?php echo $i+1; ?></a></li>

Because the numbering of the link does not follow the numbering of the number expressed in the div.

  • I have applied the solution you presented but still has the same result

  • the problem is that when I change pagination update the page and should not, I should only update the div

  • https://chat.stackexchange.com/rooms/93700/paginacao

Browser other questions tagged

You are not signed in. Login or sign up in order to post.