-4

I am trying to fix a pagination database table. After using the pagination script seen on BELOW I did not want to call the whole database, all i wanted was to call the database from a user login account and not the whole table in the database,... how can i achieve this using the pagination script below

WITHOUT PAGINATION HERE IS MY STATEMENT WHICH I USED AND IT WORK PERFECTLY

$sql = "SELECT * FROM tbl_transaction WHERE to_accno = $acc_no 
        ORDER BY id DESC LIMIT 20";
$result = dbQuery($sql);

:
=====================================
WITH PAGINATION HERE IS MY CODE BELOW
THE ISSUES IS THAT IF A LOG INTO HIS USER PANEL, IT SHOW ALL
USERS TABLE FROM DATABASE IN A USER PANEL
========================================
<?php  
//pagination.php  
require_once '../library/config.php';
require_once '../library/functions.php';

$_SESSION['user_return_url'] = $_SERVER['REQUEST_URI'];
checkUser();

 $record_per_page = 10;  
 $page = '';  
 $output = '';  
 if(isset($_POST["page"]))  
 {  
      $page = $_POST["page"];  
 }  
 else  
 {  
      $page = 1;  
 }  
 $start_from = ($page - 1)*$record_per_page;  
 $query = "SELECT * FROM tbl_transaction ORDER BY to_accno DESC LIMIT $start_from, $record_per_page";  
 $result = mysqli_query($connect, $query);  
 $output .= "  
      <table class='table table-striped table-hover table-bordered'>  
           <thead class='thead-inverse'> <tr> 
                <th>Trns Date</th>  
                <th>Description</th>  
                <th>Debit ($)</th>  
                <th>Credit($)</th>  
                <th>Remark</th>  
           </tr>  
 ";  
 while($row = mysqli_fetch_array($result))  
 {  
      $output .= '  
           <tr>  
                 <td>'.$row["tdate"].'</td>  
                 <td>'.$row["comments"].'</td> 
                 <td>'.$row["tx_type == debit ? &nbsp; . number_format($amount, 2)"].'</td>
                 <td>'.$row["tx_type == credit ? &nbsp; . number_format($amount, 2)"].'</td>
                <td>'.$row["remark"].'</td>  
           </tr>  
      ';  
 }  
 $output .= '</table><br /><div align="center">';  
 $page_query = "SELECT * FROM tbl_transaction ORDER BY to_accno DESC";  
 $page_result = mysqli_query($connect, $page_query);  
 $total_records = mysqli_num_rows($page_result);  
 $total_pages = ceil($total_records/$record_per_page);  
 for($i=1; $i<=$total_pages; $i++)  
 {  
      $output .= "<span class='pagination_link' style='cursor:pointer; padding:6px; border:1px solid #ccc;' id='".$i."'>".$i."</span>";  
 }  
 $output .= '</div><br /><br />';  
 echo $output;  
 ?>  
mega6382
  • 9,211
  • 17
  • 48
  • 69
  • 4
    Uhm… add a `WHERE ...` clause to your query…!? – deceze Oct 23 '17 at 11:24
  • Possible duplicate of https://stackoverflow.com/questions/5928611/find-total-number-of-results-in-mysql-query-with-offsetlimit – Tarun Oct 23 '17 at 11:26
  • 2
    $_POST is not valid for this please use as $_GET or $_REQUEST – Ravi Chauhan Oct 23 '17 at 11:28
  • can you change the CAPS for the question title and in the question body to something like lowercase or Camel Case please? This is considered as you yelling. – Funk Forty Niner Oct 23 '17 at 11:33
  • It is usually better to refine one question than to create a fresh one. Look here https://stackoverflow.com/a/46908059/2915423 , perhaps this solves both problems as the root cause looks the same. – helvete Oct 24 '17 at 16:25

1 Answers1

-2
    $perpage = 5;

    if(isset($_GET["page"])){
    $page = intval($_GET["page"]);
    }
    else {
    $page = 1;
    }
    $calc = $perpage * $page;
    $start = $calc - $perpage;

    $query = "SELECT * FROM tbl_transaction ORDER BY to_accno DESC Limit $start, $perpage";  
    $result = mysqli_query($connect, $query); 
Ravi Chauhan
  • 1,409
  • 13
  • 26