/*得到上一章和下一章的id值
(上一章 取chapter_id<$chapter_id,从大到小排,取第一个)
(下一章 取chapter_id>$chapter_id,从小到大排,取第一个)
*/
public function up_down_chapter($chapter_id, $book_id,$sign,$order)
{
$query = $this->db
->where('chapter_id '.$sign,$chapter_id)
->where('book_id', $book_id)
->order_by('chapter_id', $order)
->select('chapter_id')
->get('sto_chapter')
->row_array();
return $query;
}
注意:例子是在CI中的数据库操作
思路即:
$cid =5;//是你当前文章的编号
$sql ="select * from string_find where id>$cid and book_id= $book_id order by id desc limit 0,1"; //上一篇文章
$sql1 ="select * from string_find where id<$cid and book_id= $book_id order by id asc limit 0,1";//下一篇文章