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.
Login with Google