Use PHP and MySQL to set up counter process detailed

Source: Internet
Author: User
Tags count integer mysql php and php and mysql query create database
mysql| Process | counter | detailed

Run MYSQL.EXE
Mysql> CREATE DATABASE counter;
Query OK, 1 row affected (0.10 sec)

mysql> use counter;
Database changed

Mysql> CREATE TABLE tl (ID integer (2), Count Integer (5));
Query OK, 0 rows affected (0.21 sec)

Mysql> show columns from TL;
+-------+--------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------+------+-----+---------+-------+
| ID | Int (2) |     YES | |       NULL | |
| Count | Int (5) |     YES | |       NULL | |
+-------+--------+------+-----+---------+-------+
2 rows in Set (0.05 sec)

Mysql> select * from TL;
Empty Set (0.08 sec)

mysql> INSERT into TL (id,count) values (1,1);
Query OK, 1 row affected (0.02 sec)

Mysql> select * from TL;
+------+-------+
| ID | Count |
+------+-------+
|     1 | 1 |
+------+-------+
1 row in Set (0.03 sec)

The following writes the contents of the HTML file:


<body>

<?php
$myvar = "Number of visitors:";
Echo $myvar;
?>

<?php
Mysql_connect () or Die ("There are problems to connect to mysql!");
$query = "SELECT * from TL";
$result =mysql_db_query ("Counter", $query);
if ($result) {
$r =mysql_fetch_array ($result);
$counter = $r ["Count"];
$counter = $counter +1;
Echo $counter;
$query = "Update tl set count= ' $counter ' where id=1";
$result =mysql_db_query ("Counter", $query);
Mysql_close ();
}
?>
</body>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.