Page 1 of 1

Get Previous Next ID in Pagination script

Posted: 15 Jul 2018, 12:45
by JanMolendijk
I have a little script that have a Previous & Next button.
My problem is I want to detect & place the ID in those buttons

this is the code from the pagination

Code: Select all

  <body>
        <?php include_once 'data.php'; ?>
  <center>
            <ul class="pagination">
            <?php
                if($page_counter == 0){
                    echo "<li><a href=?start='0' class='active'>0</a></li>";
                    for($j=1; $j < $paginations; $j++) { 
                      echo "";
                   }
                }else{
                    echo "<a href=?start=$previous><button>Previous</button></a>"; 
                    for($j=0; $j < $paginations; $j++) {
                     if($j == $page_counter) {
                        echo " ";
                     }else{
                        echo " ";
                     } 
                  }if($j != $page_counter+1)
                    echo "<a href=?start=$next><button>Next</button></a>"; 
                } 
            ?>
            </ul>
            </center>  
In this part I have the ID but the problem is I can`t get it with this example <?php echo $row['notice_id'];?> to place it into the pagination.

Code: Select all

 <?php 
                    foreach($result as $row) { 
                        echo '

<div class="card"><button1>

'. $row['notice_id'] .'

<div class="time-left">
<div class="dropdown1">
  ' ;
  }
}
else {
  echo '';
}
$conn->close();
?> 
</div></div>


This is the code from <?php include_once 'data.php'; ?>

Code: Select all

<?php 
    //include configuration file
    require 'configuration.php';

    $start = 0;  $per_page = 1;
    $page_counter = 0;
    $next = $page_counter + 1;
    $previous = $page_counter - 1;
    
    if(isset($_GET['start'])){
     $start = $_GET['start'];
     $page_counter =  $_GET['start'];
     $start = $start *  $per_page;
     $next = $page_counter + 1;
     $previous = $page_counter - 1;
    }
    // query to get messages from messages table
    $q = "SELECT * FROM group_notice LIMIT $start, $per_page";
    $query = $db->prepare($q);
    $query->execute();

    if($query->rowCount() > 0){
        $result = $query->fetchAll(PDO::FETCH_ASSOC);
    }
    // count total number of rows in students table
    $count_query = "SELECT * FROM group_notice";
    $query = $db->prepare($count_query);
    $query->execute();
    $count = $query->rowCount();
    // calculate the pagination number by dividing total number of rows with per page.
    $paginations = ceil($count / $per_page);
?>
I hope you can help me out....

Get Previous Next ID in Pagination script

Posted: 16 Jul 2018, 06:28
by Admin
Sorry, I not understand your code, not know what it is not working.
Where in the pagination you add $row['notice_id']?
Do you get any error, or what value the $row['notice_id'] returns?

For pagination script, I use the php class from the page:
//coursesweb.net/php-mysql/pagination-class-script_s2