Show the Number of Users Online

Learn how to add upload a file using the power of PHP.

Spreadshirt
This script will explain how to display the number of users online using your website. You have to put this on everypage you want it to appear. It can be broken down into 2 sections. The first is creating the table, and the second is the PHP script itself. Beware you should have knowledge of PHP before attempting this. We also reccommend you have PhpMyAdmin :)

Alright log on to PhpMyAdmin and make a new database called "users". We are going to insert 3 fields into a new table called useronline called timestamp, ip, and file. Lets dump the following code into the Users database using the form on the PhpMyAdmin page:
CREATE TABLE useronline (
timestamp int(15) DEFAULT '0' NOT NULL,
ip varchar(40) NOT NULL,
file varchar(100) NOT NULL,
PRIMARY KEY (timestamp),
KEY ip (ip),
KEY file (file)
);

List of Reserved Words in MySQL

Before getting to far into planning, there is a number of words that you cannot use for your table and column names. MySQL uses some specific words for command processing, so using them in your own coding may confuse things a bit.


ADD
ALL
ALTER
ANALYZE
AND
AS
ASC

Data Types in MySQL

Once you have your table data organized, the next step is to figure out the data type. There are three main types : text, numbers, and Dates/Times. Choosing the column types specifies what information can or can't be stored in a table cell. Using the most correct option for each column is important as it may affect the database's overall performance.

TEXT TYPES:
CHAR( )                  - A fixed section from 0 to 255 characters long.
VARCHAR( )          - A variable section from 0 to 255 characters long.
TINYTEXT            - A string with a maximum length of 255 characters.
TEXT                      - A string with a maximum length of 65535 characters.
BLOB                      - A string with a maximum length of 65535 characters.
MEDIUMTEXT     - A string with a maximum length of 16777215 characters.
MEDIUMBLOB     - A string with a maximum length of 16777215 characters.
LONGTEXT           - A string with a maximum length of 4294967295 characters.
LONGBLOB           - A string with a maximum length of 4294967295 characters.