我正在尝试为我们的状态表创建一个分页,但是所显示的记录与我要显示的记录不符。这是我的代码:
<?php
$query = mysqli_query($connect,"SELECT * FROM inventory_item ") or die ("Error: Could not fetch rows!");
$count = 0;
if (isset($_GET['page_no']) && $_GET['page_no']!="") {
$page_no = $_GET['page_no'];
} else {
$page_no = 1;
}
$total_records_per_page = 3;
$offset = ($page_no-1) * $total_records_per_page;
$previous_page = $page_no - 1;
$next_page = $page_no + 1;
$adjacents = "2";
$query_count = mysqli_query($connect,"SELECT COUNT(*) As total_records FROM `inventory_item`");
$total_records = mysqli_fetch_array($query_count);
$total_records = $total_records['total_records'];
$total_no_of_pages = ceil($total_records / $total_records_per_page);
$second_last = $total_no_of_pages - 1;
$result = mysqli_query($connect,"SELECT * FROM `inventory_item` LIMIT $offset, $total_records_per_page");
while ($row = mysqli_fetch_array($query))
{
$item_name = $row ['item_name'];
echo '<tr><td>'.$row['item_name']. '</td><td>'.$row['description']. '</td><td>'.$row['unit'].'</td>
<td>'.$row['quantity']. '</td><td>'.$row['price']. '</td>
<td>'.$row['price'] * $row['quantity'].'</td>
<td>'.$row['status'].'</td>
<td><a href="inventory_statusEditRecordsFinal1.php?CO='.$item_name.'" title="Click to edit records" class="buttonn"/> Edit </a></td>
<td><a href="inventory_deletestatusFinal.php?item_name='.$item_name.'" title="Click to delete records" class="delbutton" onclick="return ConfirmDelete()"/> Delete </a></td>
</tr>';
}
mysqli_close($connect);
?>
Here's the result, I wanted to display 3 records per page but it displays all the data.