I have 2 files. There are showReport.php and paging.php. The codes are fine, no errors, but it showing incorrect results. Can you help me for my final exams? Because I've tried to change it but still doesn't work. Please ignore for the variable name or table name, because I'm using Indonesian.
showReport.php
<?php
$query = mysql_query("select * from barang");
$item_per_page = 2; // tambahan
paging( $query,$item_per_page );
$limitt = ($page - 1) * $item_per_page;
$query_ = mysql_query("SELECT * FROM barang ORDER BY id_transaksi DESC LIMIT $limitt, $item_per_page"); // tmbh
$sql_ = mysql_query($query_);
$i = 1;
while ($data = mysql_fetch_array($query)) {
?>
<tr class="<?php if ($i % 2 == 0) { echo "odd"; } else { echo "even"; } ?>">
<td><?php echo $i; ?></td>
<td>
<?php
echo $data['tanggal'];
//previlege admin
if ($_SESSION['role'] == 'operator') {
?>
<div class="row-actions">
<a href="edit_barang.php?uid=<?php echo $data['id_transaksi'];?>">Update</a>
| <a href="delete_barang.php?uid=<?php echo $data['id_transaksi'];?>" onClick="return confirm('Delete this report?')" class="delete">Delete</a>
</div>
<?php } ?>
</td>
<td><?php echo $data['barang_in']; ?></td>
<td><?php echo $data['bijih_out']; ?></td>
<td><?php echo $data['htm_out']; ?></td>
<td><?php echo $data['pth_out']; ?></td>
<td><?php echo $data['bijih']; ?></td>
<td><?php echo $data['kantong_htm']; ?></td>
<td><?php echo $data['kantong_pth']; ?></td>
<td><?php echo $data['note']; ?></td>
</tr>
<?php
$i++;
}
?>
paging.php
<?php
function paging($query,$item_per_page){
$page = isset($_GET['page']) ? $_GET['page'] : 1 ;
if( ( $page < 1) && (empty( $page ) ) ){
$page=1;
}
$sql = mysql_query( $query_);
$amount_data = mysql_num_rows($query);
$amount_page = ceil( $amount_data/$item_per_page );
if( $page>$amount_page ){
$page=$amount_page;
}
$lanjut = $page + 1;
$sebelum = $page - 1;
?>
<style type="text/css">
.tengah {
text-align: center;
}
</style>
<?php echo $page;?> dari <?php echo $amount_page;?><br />
<a href="?page=1"></a><a href="?page=<?php echo $sebelum; ?>">sebelumnya</a>;
||
<a href="?page=<?php echo $lanjut;?>">selanjutnya</a><a href="?page=<?php echo $jumlah_hal;?>"></a>
Ke Halaman: <form action="" method="get"><input type="text" name="page"><input type="submit" value="Go"></form>
<?php
}
?>
The number of pages are right, but it still showed all of data in one page. For example I have 4 data, I wanna show just 2 data for each page. So number of pages are 2 ( right ), but why my data won't to show 2 data for each page? Thank you in advance