温馨提示:这篇文章已超过518天没有更新,请注意相关的内容是否还可用!
分享一段更高效的帝国cms调用上一篇下一篇方法,支持重复多次调用,但只查一次数据库。
查询SQL
<?PHP
//上下翻页
$goPage = [
'prev' => ['text' => '上一题'],
'next' => ['text' => '下一题']
];
$sql = $empire->query("(SELECT titleurl, id, title FROM `{$dbtbpre}ecms_news` WHERE `id` < " . $navinfor['id'] . " AND `classid` = " . $navinfor['classid'] . " ORDER BY `id` DESC LIMIT 1) UNION (SELECT titleurl, id, title FROM `{$dbtbpre}ecms_news` WHERE `id`> " . $navinfor['id'] . " AND `classid` = " . $navinfor['classid'] . " ORDER BY `id` LIMIT 1)");
if(0 < $empire->num1($sql)) {
while($r = $empire->fetch($sql)){
$key = isset($r['id']) && $r['id'] > $navinfor['id'] ? 'next' : 'prev';
$goPage[$key]['title'] = $r['title'];
$goPage[$key]['titleurl'] = sys_ReturnBqTitleLink($r);
}
}
?>
显示代码
<?php foreach($goPage as $type => $page):?>
<div class="col-sm-6 mb-5">
<div class="card">
<div class="card-body position-relative">
<?php if(isset($page['title'])):?>
<a href="<?php echo $page['titleurl'];?>" tltle="<?php echo $page['title'];?>" class="btn btn-danger stretched-link"><?php echo $page['text'];?></a>
<?php else:?>
<a href="JavaScript:;" class="btn btn-primary disabled" role="button" aria-disabled="true"><?php echo $page['text'];?></a>
<?php endif;?>
</div>
</div>
</div>
<?php endforeach;?>
还没有评论,来说两句吧...