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.
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.
- IT / Misc 08.07.21 How to make a free translation for a website without an API, translate documents in Google Translate
- IT / Misc 06.07.21 How to make a subscription button on a website, a subscriber base and automatic mailing
- Food / Misc 06.07.21 How to quickly cook delicious fried pies with potatoes and onions
- IT / Misc 04.07.21 Caching - create, load and reset. Where to store the cache, methods and types of caching
- IT / Database 03.07.21 Custom NoSQL - storing data in files and not only in a database. Storing settings, small data and caching files