Dohn Joe
Dohn Joe

Reputation: 23

How could i limit the amount of displayed comments

My knowledge in PHP is very limited so i ask right away.

I'm using an on Bootstrap based site and i get initially 13 comments (max) displayed as default per post before a "read more comments" shows up.

I'm looking for a way to limit the displayed comments to 2 instead of 13 comments.

Has someone the necessary knowledge how to achieve this?

Thanks a ton in advance

            <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>```

Upvotes: 0

Views: 141

Answers (2)

Hasitha Jayawardana
Hasitha Jayawardana

Reputation: 2436

You can use the MySQL LIMIT clause. The MySQL LIMIT clause is used to specify the number of records to return. So in your case, you need to select only 2 out of 13 from the table comments. The SQL query would then look like this,

$SQL = "SELECT * FROM comments WHERE post_id = ? LIMIT 2";

You can read more from here.

Upvotes: 0

Joseph
Joseph

Reputation: 6269

in your SQL query add limit 2 at the end of your query

for example

SELECT * FROM comments WHERE post_id = ? LIMIT 2

Upvotes: 1

Related Questions