How to create a counter using PHP and MYSQL

Source: Internet
Author: User
Run MySQL (the best combination with PHP ). EXEMySQL (the best combination with PHP) & gt; createdatabasecounter; QueryOK, 1 rowaffected (0.10sec) MySQL (the best combination with PHP) & gt; usecounter; databasechangedMySQL (best combination with PHP)

Run MySQL (the best combination with PHP). EXE
MySQL (the best combination with PHP)> create database counter;
Query OK, 1 row affected (0.10 sec)

MySQL (the best combination with PHP)> use counter;
Database changed

MySQL (best combination with PHP)> create table tl (id integer (2), count integer (5 ));
Query OK, 0 rows affected (0.21 sec)

MySQL (best combination with PHP)> 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 (the best combination with PHP)> select * from tl;
Empty set (0.08 sec)

MySQL (best combination with PHP)> insert into tl (id, count) values );
Query OK, 1 row affected (0.02 sec)

MySQL (the best combination with PHP)> select * from tl;
+ ------ + ------- +
| Id | count |
+ ------ + ------- +
| 1 | 1 |
+ ------ + ------- +
1 row in set (0.03 sec)

Write the following HTML file content:



$ Myvar = "visitors :";
Echo $ myvar;
?>

MySQL (the best combination with PHP) _ connect () or die ("there are problems to connect to MySQL (the best combination with PHP )! ");
$ Query = "select * from tl ";
$ Result = MySQL (the best combination with PHP) _ db_query ("counter", $ query );
If ($ result ){
$ R = MySQL (the best combination with PHP) _ fetch_array ($ result );
$ Counter = $ r ["count"];
$ Counter = $ counter + 1;
Echo $ counter;
$ Query = "update tl set count = $ counter where id = 1 ";
$ Result = MySQL (the best combination with PHP) _ db_query ("counter", $ query );
MySQL (the best combination with PHP) _ close ();
}
?>

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.