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
  • 相关阅读:
    第十五篇 Django Rest Framework
    第十四篇 Mongodb数据库
    Redis相关操作
    celery
    vscode
    VScode-HTML
    第十三篇 Scrapy框架
    第十二篇 Flask 【进阶篇】 插件-SQLAlchmey等
    附录:1装饰器-functools使用
    第十二篇 Flask 基础篇
  • 原文地址:https://www.cnblogs.com/yuexin/p/3394470.html
Copyright © 2011-2022 走看看