Pagination tableau PHP

<?php

$rowperpage = 10;
$row1 = 0;

// Previous Button
if(isset($_POST['but_prev'])){
        $row1 = $_POST['row1'];
        $row1 -= $rowperpage;
        if( $row1 < 0 ){
                $row1 = 0;
        }
}

// Next Button
if(isset($_POST['but_next'])){
        $row1 = $_POST['row1'];
        $allcount = $_POST['allcount'];
        $val = $row1 + $rowperpage;
        if( $val < $allcount ){
                $row1 = $val;
        }
}

$sql = "SELECT COUNT(*) AS cntrows FROM table";
$result = mysqli_query($conn,$sql);
$fetchresult = mysqli_fetch_array($result);
$allcount = $fetchresult['cntrows'];

$sql = "SELECT * FROM table";
$result = mysqli_query($conn, $sql);
?>

</br>

<div class="table-responsive">
        <table id="myTable" class="table table-striped">
                <tr>
                        <th>Nom</th>
                        <th>Email</th>
                </tr>
                <?php
                        if(mysqli_num_rows($result) > 0) {
                                while($row = mysqli_fetch_array($result)) {
                ?>
                <tr>
                        <td><?php echo $row["nom"];?></td>
                        <td><?php echo $row["email"];?></td>
                </tr>
                <?php
                                }
                        }
                ?>
        </table>
</div>
<form method="post" action="">
            <div id="div_pagination">
                <input type="hidden" name="row1" value="<?php echo $row1; ?>">
                <input type="hidden" name="allcount" value="<?php echo $allcount; ?>">
                <input type="submit" class="button" name="but_prev" value="Previous">
                <input type="submit" class="button" name="but_next" value="Next">
            </div>
</form>