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.
- 09.07.22IT / Misc Convert office files DOC, DOCX, DOCM, RTF to DOCX, DOCM, DOC, RTF, PDF, HTML, XML, TXT formats without loss and markup changes
- 07.07.22IT / Safety How to protect PHP, JS, HTML, CSS source code - obfuscation, minification, compression and encryption
- 06.07.22IT / Safety Connection not secure, problem with Lets Encrypt - how to fix expired 09/30/2021 DST Root CA X3, remove it manually and install ISRG Root X1. Example on MS Windows 7
- 08.07.21IT / Misc How to make a free translation for a website without an API, translate documents in Google Translate
- 06.07.21IT / Misc How to make a subscription button on a website, a subscriber base and automatic mailing