search
HomeBackend DevelopmentPHP Tutorialphp+mysql article views statistics and publishing time_PHP tutorial
php+mysql article views statistics and publishing time_PHP tutorialJul 13, 2016 am 10:46 AM
php+mysqlintroducereleasearticletimefrequencyBrowsestatistics

This article will introduce you to an example of php+mysql article views statistics and release time. If you need this, feel free to refer to it.

A web page can display the "file upload time" and "number of viewers", which is not only a record of the article's history, but also reflects the article's popularity with the audience. There must be many ways to record "file upload time" and "number of viewers". The author wrote one using php+mysql based on my own understanding. I don't know if the code is optimized enough, but it feels good to use and there are no problems. I will write it down and share it with everyone. .

Thoughts

1. When uploading an article, first write the "webpage address", "upload time time()" and "counting starting point 0" in the database.

2. When the user opens the webpage, first use $_SESSION["article"] to determine whether it is online. If it is not online, open the database, take out the original count, add 1, and then update the database. Prevent online users from "refreshing" and inflating the count.

3. Open and take out the last updated count and display it on the web page.

Example

In front of write:

//Check whether the record of $stsfile already exists. If it does not exist, insert the time and counting base 0. If it exists, add 1 and update the count.
$sql = "SELECT * FROM statistics WHERE `StsFile`= '$stsfile'";
$result=mysql_query($sql);
$row = mysql_fetch_array($result);
If (empty($row['StsID']))
{
The code is as follows
 代码如下 复制代码

session_start();
$stsfile = "10001.php";
$nowtime = time();
date_default_timezone_set("Asia/Chongqing");//设置时间标准
If (!isset($_SESSION['article']) || $_SESSION['article'] != $stsfile ) //判断用户是否在线
{
$link = mysql_connect("localhost","库名","密码") or die ("打开数据库失败");
mysql_select_db("库名",$link); //连接数据库
mysql_query("set names 'utf8'"); //设置存取编码

//查询$stsfile的记录是否已经存在,如果不存在就插入时间及计数基数0,如果存在,则+1,更新计数。
$sql = "SELECT * FROM statistics WHERE `StsFile`= '$stsfile'";
$result=mysql_query($sql);
$row = mysql_fetch_array($result);
If (empty($row['StsID']))
{


 
mysql_query("INSERT INTO `statistics`(`StsFile`,`StsTime`,`StsNumb`) VALUES ('$stsfile','$nowtime','0')");
session_start();
$_SESSION['article'] = $stsfile;
}
Else
{
$numb = $row['StsNumb']+1;
mysql_query("UPDATE `statistics` SET `StsNumb` = '$numb' WHERE `StsFile` = '$stsfile'");
session_start();
$_SESSION['article'] = $stsfile; //写下$_SESSION[]
}
}
?>

Copy code

 代码如下 复制代码

$link = mysql_connect("localhost","库名","密码") or die ("打开数据库失败");
mysql_select_db("库名",$link); //连接数据库
mysql_query("set names 'utf8'"); //设置存取编码
$sql = "SELECT * FROM statistics WHERE `StsFile`= '$stsfile'";
$result=mysql_query($sql);
$row = mysql_fetch_array($result);
echo "上传时间:".date("Y-m-d H:i:s",$row['StsTime'])." 浏览数:".$row['StsNumb'];

 ?>

session_start();
$stsfile = "10001.php";
$nowtime = time();
date_default_timezone_set("Asia/Chongqing");//Set the time standard
If (!isset($_SESSION['article']) || $_SESSION['article'] != $stsfile ) //Determine whether the user is online
{
$link = mysql_connect("localhost","library name","password") or die ("Failed to open database");
mysql_select_db("Library name",$link); //Connect to database
mysql_query("set names 'utf8'"); //Set access encoding


mysql_query("INSERT INTO `statistics`(`StsFile`,`StsTime`,`StsNumb`) VALUES ('$stsfile','$nowtime','0')");
session_start();
$_SESSION['article'] = $stsfile;
}
Else
{
$numb = $row['StsNumb']+1;
mysql_query("UPDATE `statistics` SET `StsNumb` = '$numb' WHERE `StsFile` = '$stsfile'");
session_start();
$_SESSION['article'] = $stsfile; //Write $_SESSION[]
}
}
?>

The display part of the web page is the part after :
The code is as follows Copy code
$link = mysql_connect("localhost","library name","password") or die ("Failed to open database");
mysql_select_db("Library name",$link); //Connect to database
mysql_query("set names 'utf8'"); //Set access encoding
$sql = "SELECT * FROM statistics WHERE `StsFile`= '$stsfile'";
$result=mysql_query($sql);
$row = mysql_fetch_array($result);
echo "Upload time:".date("Y-m-d H:i:s",$row['StsTime'])." Number of views: ".$row['StsNumb']; ?>
http://www.bkjia.com/PHPjc/632919.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632919.htmlTechArticleThis article will introduce you to an example of php+mysql article views statistics and publishing time. If you have any questions about this Please refer to it if you need to enter. A web page can display when files are uploaded...
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
今日头条发布文章怎么才能有收益?今日头条发布文章获得更多收益方法!今日头条发布文章怎么才能有收益?今日头条发布文章获得更多收益方法!Mar 15, 2024 pm 04:13 PM

一、今日头条发布文章怎么才能有收益?今日头条发布文章获得更多收益方法!1.开通基础权益:原创文章选择投放广告可获得收益,视频必须要原创横屏才会有收益。2.开通百粉权益:粉丝量达到百粉以上,微头条、原创问答创作及问答均可获得收益。3.坚持原创作品:原创作品包含文章、微头条及问题等,要求300字以上。注意违规抄袭作品作为原创发布,会被扣信用分,即使有收益也会被扣除。4.垂直度:做专业领域一类的文章,不能随意跨领域写文章,会得不到合适的推荐,达不到作品的专和精,难以吸引粉丝读者。5.活跃度:活跃度高,

如何在uniapp中实现数据统计和分析如何在uniapp中实现数据统计和分析Oct 24, 2023 pm 12:37 PM

如何在uniapp中实现数据统计和分析一、背景介绍数据统计和分析是移动应用开发过程中非常重要的一环,通过对用户行为的统计和分析,开发者可以深入了解用户的喜好和使用习惯,从而优化产品设计和用户体验。本文将介绍如何在uniapp中实现数据统计和分析的功能,并提供一些具体的代码示例。二、选择合适的数据统计和分析工具在uniapp中实现数据统计和分析的第一步是选择合

Vue框架下,如何快速搭建统计图表系统Vue框架下,如何快速搭建统计图表系统Aug 21, 2023 pm 05:48 PM

Vue框架下,如何快速搭建统计图表系统在现代网页应用中,统计图表是必不可少的组成部分。Vue.js作为一款流行的前端框架,提供了很多便捷的工具和组件,能够帮助我们快速搭建统计图表系统。本文将介绍如何利用Vue框架以及一些插件来搭建一个简单的统计图表系统。首先,我们需要准备一个Vue.js的开发环境,包括安装Vue脚手架以及一些相关的插件。在命令行中执行以下命

Vue统计图表的线性、饼状图功能实现Vue统计图表的线性、饼状图功能实现Aug 19, 2023 pm 06:13 PM

Vue统计图表的线性、饼状图功能实现在数据分析和可视化领域,统计图表是一种非常常用的工具。Vue作为一种流行的JavaScript框架,提供了便捷的方法来实现各种功能,包括统计图表的展示和交互。本文将介绍如何使用Vue来实现线性和饼状图功能,并提供相应的代码示例。线性图功能实现线性图是一种用于展示数据趋势和变化的图表类型。在Vue中,我们可以使用一些优秀的第

如何使用MySQL的COUNT函数统计数据表的行数如何使用MySQL的COUNT函数统计数据表的行数Jul 25, 2023 pm 02:09 PM

如何使用MySQL的COUNT函数统计数据表的行数在MySQL中,COUNT函数是一个非常强大的函数,用于统计数据表中满足特定条件的行数。本文将介绍如何使用MySQL的COUNT函数来统计数据表的行数,并提供相关的代码示例。COUNT函数的语法如下:SELECTCOUNT(column_name)FROMtable_nameWHEREconditi

在Beego中使用Google Analytics统计网站数据在Beego中使用Google Analytics统计网站数据Jun 22, 2023 am 09:19 AM

随着互联网的快速发展,Web应用程序的使用越来越普遍,如何对Web应用程序的使用情况进行监控和分析成为了开发者和网站经营者的关注点。GoogleAnalytics是一种强大的网站分析工具,可以对网站访问者的行为进行跟踪和分析。本文将介绍如何在Beego中使用GoogleAnalytics来统计网站数据。一、注册GoogleAnalytics账号首先需要

统计分析法的步骤统计分析法的步骤Jun 28, 2023 pm 03:27 PM

统计分析,常指对收集到的有关数据资料进行整理归类并进行解释的过程。统计分析的基本步骤包括:1、收集数据;2、整理数据;3、分析数据。

如何确认 iPhone 15 系列电池的充电计次?如何确认 iPhone 15 系列电池的充电计次?Oct 30, 2023 pm 08:13 PM

苹果的iPhone电池,因为用户经常使用的关系,因此损耗是比一般电子产品更快,而一般的iPhone电池设计,是可以在日常生活中,循环充电500次,仍然有原效能的80%容量,但如何才能知道你iPhone的电池充电次数?首先进入设定,一般关于本机最低有电池,就可以看到

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment