[英]how to limit the amount of comments or replies to comments a user can post per day
[英]How could i limit the amount of displayed comments
我在 PHP 方面的知識非常有限,所以我馬上問。
我正在使用基於 Bootstrap 的網站,在出現“閱讀更多評論”之前,我最初會在每個帖子中默認顯示 13 條評論(最多)。
我正在尋找一種將顯示的評論限制為 2 條而不是 13 條評論的方法。
有人有必要的知識如何實現這一目標嗎?
提前致謝
<li class="pp_post_comms hidden"></li>
<?php if ($post_data['comments']) {
foreach ($post_data['comments'] as $key => $comment) {
include 'comments.html';
} } ?>
<?php if ($post_data['votes'] > 4) { ?>
<li class="load-comments">
<button onclick="load_tlp_comments(<?php echo $post_data['post_id']; ?>,this);">{{LANG show_more}} {{LANG comments}}</button>
</li>
<?php } ?>
</ul>```
在您的SQL
查詢中,在查詢末尾添加limit 2
例如
SELECT * FROM comments WHERE post_id = ? LIMIT 2
您可以使用 MySQL LIMIT
子句。 MySQL LIMIT
子句用於指定要返回的記錄數。 因此,在您的情況下,您只需要 select 表中的 13 條comments
中的 2 條。 SQL 查詢將如下所示,
$SQL = "SELECT * FROM comments WHERE post_id = ? LIMIT 2";
您可以從這里閱讀更多內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.