下一页和上一页实现方法

实现php代码

$nextPage     = "";
$previousPage = "";
$url          = "";
$muUrl        = "";
$id           = !empty($_POST['id'])?intval($_POST['id']):0;
$dbName       = "";
if(empty($id)){
    throw new Exception('id不能为空');
}
$sql = "select id from `{$dbName}` where id>'{$id}' order by id asc limit 1";
$result = mysqli_query($conn,$sql);
$row = mysqli_fetch_row($result);
if(empty($row)){
    $nextPage = '没有';
}else{
    $nextPage = '<a href="'.$url.'">下一章</a>';
}

$sql1 = "select id from `{$dbName}` where id<'{$id}' order by id desc limit 1";
$result1 = mysqli_query($conn,$sql1);
$row1 = mysqli_fetch_row($result1);
if(empty($row)){
    $previousPage = '没有';
}else{
    $previousPage = '<a href="'.$url.'">上一章</a>';
}
echo $previousPage.' <a href="'.$muUrl.'">返回目录</a> '.$nextPage;
exit;

js代码

<script>
    $.post('',{},function(data){
        $('#page').empty();
        $('#page').append(data);
    });
</script>
标签:
无标签

相关文章

发表评论