# 帝国CMS高效重复调用上一篇下一篇SQL写法

*Published:* 2023-10-30
*Author:* 客服001

#### 温馨提醒

如果文章内容或图片资源失效，请留言反馈，我们会及时处理，谢谢

本文最后更新于2023年10月30日，已超过 180天没有更新



查询SQL：

```
<?php
//上下翻页
$goPage = [
    'prev'        => ['text' => '上一题'],
    'next'         => ['text' => '下一题']
];
$<a class="tag_link" href="https://www.xarjtc.com/tag/sql" target="_blank" title="查看sql此标签更多文章"><abbr title="">sql</abbr></a> = $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;?>
```