Home >Backend Development >PHP Tutorial >Super simple php image statistician_PHP tutorial
Super simple php image statistician. I used to make this kind of statistician using txt files. Now I will implement it directly using the database. Let’s take a look at the data structure first.
CREATE TABLE `count` (
`id` int(10) NOT NULL auto_increment,
`value` varchar(20) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=gb2312 AUTO_INCREMENT=98 ;
Now that the data is ready, let’s take a look at how the program is implemented.
//Add a record when browsing the page to increase the visit by 1.
$conn=mysql_connect("localhost","root","root");
//echo mysql_error();
mysql_query("set names gb2312");
mysql_select_db("guest");
$sql="INSERT INTO `count` ( `id` , `value` ) VALUES ('', '32')";
$result=mysql_query($sql);
if ($result) {
echo "Insertion successful.";
}
mysql_close($conn);
//Read the record data count(*)
$conn=mysql_connect("localhost","root","root");
//echo mysql_error();
mysql_query("set names gb2312");
mysql_select_db("guest");
$mysql="select * from `count`";
$result=mysql_query($mysql);
$row=mysql_num_rows($result);
for($i=0;$i
$a=substr($row,$i,1);
$str.= "";
}
?>