zoukankan      html  css  js  c++  java
  • 文章的上一章下一章

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

    我们只需要知道小说的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
  • 相关阅读:
    SharePoint Framework (SPFx) 开发入门教程
    SharePoint 2013 Designer 入门教程
    SharePoint 2013 开发教程
    SharePoint 2013 入门教程
    SharePoint Online 部署SPFx Web部件
    SharePoint Online SPFx Web部件绑定数据
    SharePoint Online 创建SPFx客户端Web部件
    SharePoint Online 配置框架(SPFx)开发环境
    SharePoint Online 创建应用程序目录
    SharePoint Online 启用 IRM
  • 原文地址:https://www.cnblogs.com/yuexin/p/3394470.html
Copyright © 2011-2022 走看看