gpt4 book ai didi

php - 仅显示 10 条记录,然后单击按钮显示所有记录

转载 作者:行者123 更新时间:2023-11-30 21:44:57 27 4
gpt4 key购买 nike

我想知道如何限制显示的记录,例如限制为 10,之后他们需要成为一个按钮才能获得所有主题。我想知道如何以这种方式显示它

函数代码:

public function get_topics(){
$getTopic = $this->database->query("
SELECT topics.*, klanten.foto, klanten.voornaam, boards.topic, ledenpagina.ledenpagina_id, klanten.achternaam FROM topics
LEFT JOIN ledenpagina ON ledenpagina.ledenpagina_id = topics.ledenpagina_id
LEFT JOIN klanten ON topics.klant_id=klanten.id
LEFT JOIN boards ON topics.board_id=boards.id
WHERE ledenpagina.ledenpagina_id=:ledenpagina_id
ORDER BY id ASC");
$this->database->bind(":ledenpagina_id", $_SESSION['ledenpagina_id']);
$topics = $this->database->resultset();

return $topics;
}

PHP代码:

<section class="col-md-8 connectedSortable">
<div class="clearfix paddingbottom10"></div>
<div class="box box-info">
<div class="panel panel-default">
<div class="panel-heading main-color-bg">
<h3 class="panel-title">Topics</h3>
</div>
div class="panel-body">
<?php
$toppic = $app->get_topics();
foreach($toppic as $topic){

echo '<a href="https://####/reactie"> <div id="topic">';
echo '<div id="topicimg">';
if(file_exists('assets/images/profielfotos/'.$topic['klant_id'])) {
echo '<img class="img-circle" src="/assets/images/profielfotos/'.$topic['klant_id'].'/'.$topic['foto'].'" />';
} else {
echo '<i class="fa fa-fw fa-user img-circle"></i>';
}
echo '</div><div id="topictekst">';
echo '<b>'.$topic['topicnaam'].'</b>';
echo ' - ' . $topic['voornaam'] . " " . $topic['achternaam'] ;
echo '<span style="float:right; margin-top:15px; margin-left:5px;">'.implode($app->count_reactie($topic['id'])) .' reacties</span> <span style="float:right; color:lightgrey; margin-top:15px"class="fa fa-comment"></span>';
echo '<hr><span class="badge bg-red">' . implode($app->boards($topic['board_id'])) . '</span>';
echo ' laatste reactie: ' .$app->tijd_reactie($topic['id']) . ' door ' .$app->reactieDoor($topic['id']);
echo '</div></div></a>';
}
?>

</div>
</div>
/div><!-- /.box -->
</section><!-- right col -->

这是我的第一个问题,所以请不要对我太苛刻

最佳答案

Paging by SQL可以通过 ORDER BY 子句上的新功能实现,例如 Offset 和 Fetch Next

这是一个示例查询

SELECT * FROM TableName ORDER BY ID OFFSET 10 ROWS FETCH NEXT 10 ROWS ONLY

如果您将偏移量参数化为(页码 * 页行数),您可以为您的网页构建分页结构

关于php - 仅显示 10 条记录,然后单击按钮显示所有记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49900064/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com