Technical Help /php /chat

A web Chat Application

Creating a web Chat Application we will need to do a few things:

  1. Figure out our Data - and Make a Database with a Table and the Fields we need - MySQL
  2. Figure out our Work flow
  3. Create an HTML interface (HTML, CSS and JavaScript
  4. Change the HTML interface into PHP and pull data from database and from "local" paramaters
  5. Create a php file to deal with the program logic - inserting data

Starting with HTML Design

There is a concept in web development which I subscribe to called design first development. This is a dangerous thing to do if you don't know much about application development. It sometimes gets similar criticism that Bruce Lee's martial art does. In design first you make your html document and then change it to be an application.

I went ahead and made a base chat html document view_messages.html|http://danm.ucsc.edu/~lyle/classes/php/chat/view_messages.html].

About view_messages.html

A few things to note about our html document (do a view source of that document):

Looks like: <div id="chat_log">.......</div>

And inside that chat_log I have a bunch of messages each inside a div. And each message has a person's name.

Database - MySQL

MySQL

MySQL is an open source database that is very common with web development. A bit about what a database is.

phpMyAdmin

To manage MySQL you will usually use phpMyAdmin which is a php web application that allows you to manage a MySQL server.

Our Table

We need a table to hold our chat messages. We will call the table "messages" and the table will have these fields:

Before Starting to code, workflow

You need to figure out how this application will work from a logic perspective. We are going to have two basic work-flows that will interact with each-other.

View Messages

The view_messages workflow is fairly straight forward and doesn't need a large diagram. It is fairly linear.

  1. Start / Browser asks for page
  2. Get all the messages from the database ordered by their creation date.
  3. Render the HTML

    Include the chat messages, notifications to the user, and insert their name/created_by if you know it.

Add Message

The add_messages workflow has some more complications. Here is a work flow diagram:

Part II: Let's code


Page Details
Contact DANM  |  Digital Arts and New Media  |  Arts Division  |  Grad Division
login