I would like to implement the "View Count" function on the bulletin board in node.js.

Asked 2 years ago, Updated 2 years ago, 36 views

Hello, I'm making a web page with node.js.

DB is using mysql, and I want to increase the view count when I press the post.

/////////////////////////

router.get('/read/:idx',function(req,res,next) // When inquiring, logic processing statement

{

var idx = req.params.idx;

pool.getConnection(function(err,connection)
{
    var sql = "select idx, creator_id, title, content, date_format(modidate,'%Y-%m-%d %H:%i:%s') modidate, hit from board where idx=?";
    connection.query(sql,[idx], function(err,row)
    {
        if(err) console.error(err);

        res.render ('read', {title:"text content", row:row[0]});
        connection.release();
    }); });

It looks like this When rendering it as a read page here, I want to make it count (hit +1) but I don't dare to catch it because it's a beginner.

Please help me!

node.js

2022-09-22 20:34

1 Answers

You can increase the value stored in the DB whenever there is a read request for the post.

UPDATE board SET hit = hit + 1 WHERE idx = 1;


2022-09-22 20:34

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.