Sign in Registration
ruen

How to make a counter of views of material on the site

The view counter can be very useful on a wide variety of sites. It allows the visitor to understand how popular the material is and how many people have read it.

kak-sdelat-schetchik-prosmotrov-materiala

The view counter is the counter of requests for this material. The counter of the number of requests can be implemented in different ways, let's consider the simplest way. To implement it, it is enough to follow a few steps:

- Create a new column in the database (in the table that stores the content data) and name it, for example, "requests". Such a column must be of type int, by default the value is 0. To do this, you can use phpMyAdmin ;

- In the function or method responsible for displaying the material, you need to add functionality that will enter the value of the view performed into the database, in the previously created column. But first you need to request the current value, only then add the number 1 (value increment) and save the data;

- Output data on the number of views on the site on the material page or in any other block. To do this, simply request the data from the saved column and display it in the material design template.

Thus, making a view counter of a material is very easy - just follow a few simple steps that were discussed above.

Comments (0)
For commenting sign in or register.

Latest articles

Popular sections

Eqsash (Tools)

Android app - VK LAST USER ID, отучитель от зависимости и т.д.:
Available on Google Play

Amessage (Communication)

Login to the web version
Android app:
Available on Google Play

Share this

Subscribe to

YouTube

Books

IT notes - In simple language about the most necessary things (HTML, CSS, JavaScript, PHP, databases, Drupal, Bitrix, SEO, domains, security and more), PDF, 500 p.