Google Login with Google

How to Implement a View Counter (PHP + MySQL)

1. Overview
A view counter is an important feature in any bulletin board, as it helps identify which content is most popular among users.

2. Database Setup
sqlALTER TABLE notices ADD views INT DEFAULT 0;

3. Incrementing the View Count
php$stmt = $conn->prepare("
UPDATE notices SET views = views + 1 WHERE id = ?
");

4. Applying It to the Post Detail Page
php$id = intval($_GET['id']);

// Increment view count
$stmt = $conn->prepare("UPDATE notices SET views = views + 1 WHERE id = ?");
$stmt->bind_param("i", $id);
$stmt->execute();

5. Displaying the View Count
phpecho $row['views'];

6. Important Notes

Do not increment the view count on the post list page
Views should only be incremented on the post detail page
Consider implementing duplicate view prevention (e.g., using sessions or cookies to avoid counting the same user multiple times)


7. Summary

View counts are incremented using an UPDATE query
The logic belongs in view.php (the post detail page)
Simple to implement, but an important feature for any content platform


💡 Pro Tip
View count data reflects real user behavior — it tells you what your audience is actually interested in, making it a valuable signal for content strategy and recommendations.
← Back to list
💬 Comments (1)
전혜주
전혜주 Apr 27, 2026 · 12:10
This is very good way to get opinions from users to improve website quality! Follow above, then process onself. This will be very helpful information, i strongly believe . And if have any further questions, leave a message hear!