• 文章的上一章下一章


    弄一个小说网站需要用到上一章下一章,这里面回顾下:

    我们只需要知道小说的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
  • 相关阅读:
    4.6--4.9
    4.表达式和运算符
    3.9--3.10
    3.8
    泛型(Generic)
    容器
    String,StringBuffer
    数组
    异常,自定义异常,异常重写
    多态,抽象类和抽象方法,接口
  • 原文地址:https://www.cnblogs.com/yuexin/p/3394470.html
Copyright © 2020-2023  润新知