分页:一个大问题

时间:2017-10-23 11:22:07

标签: php

我正在尝试修复分页数据库表。使用下面看到的分页脚本后     我不想调用整个数据库,我只想从用户登录帐户调用数据库     不是数据库中的整个表格,...我怎样才能使用下面的分页脚本实现这一目标

此处没有分页这是我使用的声明,而且我的工作完美无缺

$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;  
 ?>  

1 个答案:

答案 0 :(得分:-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); 
相关问题