Model文件
/*获取上当前文章的上下篇*/
public function getUpPost($pid){$select = $this->_db->select();
$select->from($this->_name,'*');
$select->where('pid <?',$pid);
$select->order('pid desc');
$select->limit(1);
$re = $this->_db->fetchRow($select);
return $re;
}
public function getDownPost($pid){
$select = $this->_db->select();
$select->from($this->_name,'*');
$select->where('pid >?',$pid);
$select->order('pid asc');
$select->limit(1);
$re = $this->_db->fetchRow($select);
return $re;
}
controller文件
public function viewAction()
{
$pid = $this->_request->getParam('id', '');
/*===========获取文章上一篇==================*/
$infopost = new PostModel();
$re = $infopost->getUpPost($pid);
//var_dump($re);exit;
$this->_view->reup = $re;
$uppid = $this->_view->reup['pid'];
$uppost = $this->_view->reup['title'];
/*===========获取文章下一篇==================*/
$re = $infopost->getDownPost($pid);
$this->_view->redown = $re;
$downpid = $this->_view->redown['pid'];
$downpost = $this->_view->redown['title'];
/*=============================*/
}
view文件
<div class="updownpost">
<?php if($this->reup['pid']):?>
<a href="<?php echo $this->reup['pid']?>" class="postitle tr"><?php echo $this->reup['title']?></a>
<?php else: ?>
<i class="nopost tr">暂无</i>
<?php endif; ?>
<i class="pr20"> <<上一篇</i>
<a href="javascript:window.history.back();" class="postback" style="color:#666;">[返 回]</a>
<i>下一篇>> </i>
<?php if($this->redown['pid']): ?>
<a href="<?php echo $this->redown['pid']?>" class="postitle tl"><?php echo $this->redown['title']?></a>
<?php else:?>
<i class="nopost tl">暂无</i>
<?php endif;?>
</div>