Making a Trivial Message Board
First we need to make a table in our mysql database.
We have named our database abautomatic and our user name is
test_teacher.
We will create a table with only two fields (we could have just one in theory).
One field is the message id and the second field is the actual message content. we limit the content
to 50 letters.
see this link for a list of options for creating tables:
http://dev.mysql.com/doc/mysql/en/CREATE_TABLE.html
We will use the AUTO_INCREMENT option in order to automatically increment the message id.
Note: we only made the id field AUTO_INCREMENT.
[root@esp root]# mysql -u test_teacher -p abautomatic
Enter password:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 82 to server version: 3.23.53a
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> create table test(id int NOT NULL AUTO_INCREMENT, message varchar(50), PRIMARY KEY(id));
Query OK, 0 rows affected (0.01 sec)
mysql> explain test;
+---------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+----------------+
| id | int(11) | | PRI | NULL | auto_increment |
| message | varchar(50) | YES | | NULL | |
+---------+-------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)
mysql> exit
Bye
[root@esp root]#
Then we make a php page called message.php which looks like this:
Trivial Message Board
Trivial Message Board ";
print "message number | message content |
";
while($row = mysql_fetch_array($result))
{
print "".$row['id']." | ".$row['message']." |
";
}
print "";
?>
Here is the location of the above page:
http://esp.jct.ac.il/~danzig/message.php