0
    $per_page = 3;
    $page_query = mysql_query("SELECT COUNT(*) FROM penjualan");
    $pages = ceil(mysql_result($page_query, 0) / $per_page);
    $page = (isset($_GET['pagenum'])) ? (int)$_GET['pagenum'] : $pages;
    $start = ($page - 1) * $per_page;

    $query = mysql_query("SELECT * FROM penjualan ORDER BY nonota ASC LIMIT $start, $per_page");
    while($r=mysql_fetch_array($query)){
    echo "
       <tr>
         <td><a href='?page=penjualan&nota=$r[nonota]'>$r[nonota]</a></td>
         <td>$r[tanggal]</td>
         <td>$r[total]</td>
         <td><a href='?page=penjualan&nota=$r[nonota]'>Cetak Nota</a></td>
       </tr>";
    }
    if($pages >= 1 && $page <= $pages){
    for($halaman=1; $halaman<=$pages; $halaman++){
       echo ($halaman == $page) ? '<a class="halaman-aktif">'.$halaman. '</a>' : '<a href="?page=penjualan&pagenum='.$halaman.'"> '.$halaman.'</a>';                                  }
    }

Hello I have a list of ....data... that is displayed 3 per page with the LIMIT clause.
i want when im going to this addres ?page=penjualan&nota=5 the pagination is on page 2..
other example when im going to this addres page=penjualan&nota=8 the pagination is on page 3..
because item $per_page is only 3..
pls help me.. thanks very much

Khen Imvu
  • 15
  • 5

1 Answers1

0
...
$pages = ceil(mysql_result($page_query, 0) / $per_page);
if (isset($_GET['nota'])) {
    $page = intval(((int) $_GET['nota'] - 1) / $per_page) + 1;
} else {
    $page = isset($_GET['pagenum']) ? (int) $_GET['pagenum'] : $pages;
}
$start = ($page - 1) * $per_page;
...

NOTE1: It works only when field nonota in db has all numbers consecutive (if you delete any row then you need to renumerate all higher numbers one down).

NOTE2: mysql_* functions are depreciated. Time to refactor your code to mysqli_* or PDO with special attention to prepared statements that prevent against SQL injection attacks.

Community
  • 1
  • 1
shudder
  • 2,076
  • 2
  • 20
  • 21