Efficiently implement Empire CMSPrevNextNext SQL call, easily solve the problem of repeated code

Share a more efficient method of calling the previous article and the next article of Imperial CMS, which supports repeated calls, but only checks the database once.

Query SQL
<?php
//Flip page up and down
$goPage = [
'prev' => ['text' => 'Previous question'],
'next' => ['text' => 'Next question']
] ;
$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);




}
}
?>
Display Code
<?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;?>

Guess you like

Origin blog.csdn.net/winkexin/article/details/131349976