我已经实现了php函数,它可以获取结果并使用分页显示它们。此外,我尝试在Jquery中设置单击侦听器,以从先前选择的页面中删除活动类,并将其添加到新页面。
但是,它正确切换到不同的页面,但它不会更改活动类。我正在使用simplePagination.js
if (isset($_GET["list"])) {
$page = $_GET["list"];
} else {
$page=1;
}
$limit = 10;
$start_from = ($page-1) * $limit;
$query = "SELECT * FROM users WHERE sender_id = '".$_SESSION['id']."' ORDER BY date_time DESC LIMIT $start_from, $limit";
$result = mysqli_query($link, $query);
if (mysqli_num_rows($result) == 0) {
echo "error";
} else {
echo '<br /><table class="table table-hover">
<thead>
<tr>
<th scope="col"></th>
<th scope="col">Message</th>
<th scope="col">Date</th>
</tr>
</thead>
<tbody>';
while ($row = mysqli_fetch_assoc($result)) {
echo '<tr>
<th scope="row"></th>
<td>View Message</td>
<td>'.$row['date_time'].'</td>
</tr>';
}
echo '</tbody>
</table>';
$query = "SELECT COUNT(message_id) FROM inbox";
$result = mysqli_query($link, $query);
$row = mysqli_fetch_row($result);
$total_records = $row[0];
$total_pages = ceil($total_records / $limit);
$paginationLink = "<nav><ul class='pagination'>";
for ($i = 1; $i <= $total_pages; $i++) {
$paginationLink .= "<li><a href='?page=inbox_sent&list=".$i."'>".$i."</a></li>";
};
echo $paginationLink . "</ul></nav>";
}
在我的Javascript文件中,我有这个:
$(document).ready(function(){
$('.pagination').pagination({
items: 50,
itemsOnPage: 10,
cssStyle: 'light-theme',
hrefTextPrefix: '?page=inbox_sent&list='
});
$( ".navlink" ).click(function() {
$(".navlink").removeClass('active');
$(this).addClass('active');
});
});
所有结果都正确显示,但活动的分页类始终保持不变。