Doubt in PHP Paging

Asked

Viewed 111 times

2

I’m working on a system and I’m having doubts in the pagination, I know it can have some grotesque errors because not "manjo" much.

<?php include("cabecalho.php");
include("conexao.php"); 
include("banco-dados.php"); 

    $totalReg = 11;
?>


<?php
    //$pagina = (isset($_GET['pagina']))? $_GET['pagina'] : 1;
    $pagina = $_GET['pagina']; 

    if (!$pagina) { 
        $pc = "1"; 
    } else { 
        $pc = $pagina; 
    } 

?>
<?php
    $inicio = $pc -1
?>



<?php if(array_key_exists("removido", $_GET) && $_GET['removido'] == true) : ?>
    <p class="alert-success">Chip apagado com sucesso</p>
<?php 
    endif
 ?>

<?php if(array_key_exists("add", $_GET) && $_GET['add'] == true) : ?>
    <p class="alert-success">Chip adicionado com sucesso</p>
<?php 
    endif
 ?>

 <?php if(array_key_exists("altera", $_GET) && $_GET['altera'] == true) : ?>
    <p class="alert-success">Chip alterado com sucesso</p>
<?php 
    endif
 ?>
<table class="table2 table-striped table-bordered">
    <form action="lista-chip.php" method="post">
        <tr>
            <td class="col-md-1"><input class="form-control" type="text" placeholder="Busca pelo o ddd" name="ddd"></td>
            <td class="col-md-2"><input class="form-control" type="text" placeholder="Busca pelo o telefone" name="telefone"></td>
            <td class="col-md-2"><input class="form-control" type="text" placeholder=" Busca pela a operadora" name="operadora"></td>
            <td class="col-md-1"><input class="btn btn-default" type="submit"> </td>
        </tr>
    </form>
    <tr>
        <td><h5><strong>DDD</strong></h5></td>
        <td><h5><strong>TELEFONE</strong></h5></td>
        <td><h5><strong>OPERADORA</strong></h5>
        <td><h5><strong>STATUS</strong></h5></td>
        <td><h5><strong>FUNÇÕES</strong></h5>

    </tr>
    <?php
        $inicio = $pc - 1; 
        $inicio = $inicio * $totalReg;


        $chips = listaChips($conexao, $inicio, $totalReg);
        foreach($chips as $chip) :
    ?>
    <tr>
        <td><?= $chip['DDD']; ?></td>
        <td><?= $chip['TELEFONE']; ?></td>
        <td><?= $chip['operadora_nome']; ?></td>
        <td> <?= $chip['STATUS'] != 1 ? "Desativo" : "Ativo"; ?> </td>
        <td class="col-md-1">
            <a href="lista-chip.php?id=<?=$chip['ID_CHIP']?>"><img src="imgs/atualizar.png"></a>
            <a href="editar-chip.php?id=<?=$chip['ID_CHIP']?>"><img src="imgs/edit.png"></a>
            <a onclick="return confirm('Você tem certeza que quer excluir esse item?');" href="remove-chip.php?id=<?=$chip['ID_CHIP']?>"><img src="imgs/remover.png"></a>
        </td>
    </tr>

    <?php
        endforeach  
    ?>
</table>
<?php

?>  <div class="btn-group">
        <button type="button" class="btn btn-default"><a href="chips.php?pagina='$anterior'">  Anterior</a> </button>
        <button type="button" class="btn btn-default"><a href="chips.php?pagina='$proximo'">Próxima</br></a> </button>
    </div>


<?php include("rodape.php"); ?>

when I click the button next, the following error appears

Warning: mysqli_fetch_assoc() expects Parameter 1 to be mysqli_result, Boolean Given in C: xampp htdocs managed database.php on line 25

down the function,with line 25. Someone helps me to make the system correctly apgination?

inserir a descrição da imagem aqui

  • 1

    What is your question? what error is occurring?

  • Gabriela what is your problem/doubt? I think you forgot to mention.

  • What’s the matter?

  • In order to help you need to put the exact copy error and glue what is being printed to your screen

  • I cannot do the paging, when I click on the "next" button an error appears on line 25 in the database code

  • In other words the error means the following: mysqli_fetch_assoc() expects 1 parameter to give some result. That is, the problem itself is not on line 25, but on 23, where the query is made. Put a echo $query; die(); line 23. Save and then click the next button. See what it brings in the query. Probably the variable $inicio or $totalReg is coming empty.

  • @Diegosouza with echo $query; die(); error appeared Notice: Undefined index: page in C: xampp htdocs managed ordering chips.php on line 11

  • Takes the die() and forehead again.

  • @Diegosouza, already taken, appears syntax error on line 23

  • What is this -10 in the query ? It is the variable $inicio. To make sure this is the error, copy this query and paste it into your Mysql and run. The query will return empty or give some syntax error.

  • If an error appeared in the query, I just wanted to understand what the bug of the paging code is not right,

  • So the error is there. Paging depends on the query being right.

Show 7 more comments
No answers

Browser other questions tagged

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