上一章下一章
好久不写代码了,今天突然用到了上一章下一章(一个小说网站,在这里面我用的是Thinkphp框架),就总结了下,上一章下一章,要用到书的id(bookid)和章节的id(chapterid)具体如下:
function checkChapter($bookid,$chaper){//书id,和章节id
$chapters = M("chapters");
$chapterNex = $chapters->where("acc_bookid=$bookid and acc_chapterid > $chaper")->find();//下一章
$chapterPre = $chapters->where("acc_bookid=$bookid and acc_chapterid < $chaper")->order("acc_chapterid desc")->find();//上一章
$str_chapter = '';
if(!empty($chapterPre) && empty($chapterNex)){
$str_chapter .= '<a href="'.U('Reader/index',array('bookid'=>$bookid,'chapterid'=>$chapterPre['acc_chapterid'])).'">上一章</a> <a href="'.U('View/index',array('bookid'=>$bookid)).'">返回目录</a>'; }
if(empty($chapterPre) && !empty($chapterNex)){
$str_chapter .= '<a href="'.U('View/index',array('bookid'=>$bookid)).'">返回目录</a> <a href="'.U('Reader/index',array('bookid'=>$bookid,'chapterid'=>$chapterNex['acc_chapterid'])).'">下一章</a>'; }
if(!empty($chapterPre) && !empty($chapterNex)){
$str_chapter .= '<a href="'.U('Reader/index',array('bookid'=>$bookid,'chapterid'=>$chapterPre['acc_chapterid'])).'">上一章</a> <a href="'.U('View/index',array('bookid'=>$bookid)).'">返回目录</a> <a href="'.U('Reader/index',array('bookid'=>$bookid,'chapterid'=>$chapterNex['acc_chapterid'])).'">下一章</a>'; }
return $str_chapter;
}