大家好,欢迎来到IT知识分享网。
弄一个小说网站需要用到上一章下一章,这里面回顾下:
我们只需要知道小说的Id(bookid)和当前章节Id(chapterid),查询出来当前小说的的所有章节,chapterid > 当前章节Id正序排列的第一节,即是下一张;chapterid < 当前章节id倒序排列的第一章节,即是上一张
示例代码如下:
1 <?php 2 /* 3 * 章节的上一章或者下一张 4 */ 5 function checkChapter($bookid,$chaper){ 6 $chapters = M("chapters"); 7 $count = $chapters->where("acc_bookid=$bookid")->count();//获得总共章节娄 8 $chapterNex = $chapters->where("acc_bookid=$bookid and acc_chapterid > $chaper")->find();//下一章 9 $chapterPre = $chapters->where("acc_bookid=$bookid and acc_chapterid < $chaper")->order("acc_chapterid desc")->find();//上一章 10 $str_chapter = ''; 11 if(!empty($chapterPre) && empty($chapterNex)){ 12 $str_chapter .= '<a href="'.U('Reader/index',array('bookid'=>$bookid,'chapterid'=>$chapterPre['acc_chapterid'])).'">上一章</a> 13 <a href="'.U('View/index',array('bookid'=>$bookid)).'">返回目录</a>'; 14 } 15 if(empty($chapterPre) && !empty($chapterNex)){ 16 17 $str_chapter .= '<a href="'.U('View/index',array('bookid'=>$bookid)).'">返回目录</a> 18 <a href="'.U('Reader/index',array('bookid'=>$bookid,'chapterid'=>$chapterNex['acc_chapterid'])).'">下一章</a>'; 19 } 20 if(!empty($chapterPre) && !empty($chapterNex)){ 21 $str_chapter .= '<a href="'.U('Reader/index',array('bookid'=>$bookid,'chapterid'=>$chapterPre['acc_chapterid'])).'">上一章</a> 22 <a href="'.U('View/index',array('bookid'=>$bookid)).'">返回目录</a> 23 <a href="'.U('Reader/index',array('bookid'=>$bookid,'chapterid'=>$chapterNex['acc_chapterid'])).'">下一章</a>'; 24 } 25 return $str_chapter; 26 } 27 ?>
View Code
转载于:https://www.cnblogs.com/yuexin/p/3394470.html
免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://haidsoft.com/127764.html