Im thinking about taking on a chat room php based project. I want to make sure my logic is right though. This is very raw so please feel free to contribute if you see any problems that might occur.

MYSQL

TABLES
Username
chatroom1
chatroom2
etc..

PHP

Sign up.php
Insert username and password into Username table.

Login.php
Search Username table to validate username and password. Create session.

chatroom1.php
enter message into chatroom1 table. Retrieve messages periodically by new message entered organized by timestamp.

hi
it is not understandable. i m not getting u. can u explain it in more detail.

Member Avatar for diafol

Ajax. For periodic calls to DB.

seems OK. Do you really need to create a chatroom table every time? Depends on your structure I suppose. Can users create their own chatrooms or are there a few that will be available to them?

I wanted to have a fix number of rooms. I know Yahoo got in trouble a few years ago with the creation of new chat rooms by users on yahoo messenger. I know creating a new table isn't very difficult though.

I am very green when it comes to javascript and ajax. I'm a lil intimidated actually. I understand the concept of ajax but dont really understand on how to call a database with it in conjunction with php.

Member Avatar for diafol

You won't be able to make a chat for php without ajax.

If you use jQuery, it should be quite easy.

You dont need to create a chatroom table everytime there is new chat launched. Ive never programmed a chatroom but I would guess the database would rather be two tables.
1st table for a chats with columsn for example: "id, created_by, launched, chat_title".
2nd table is all the comments with columns like, "idnumb, chatid_FK(referencing the 1st table and linking the id together), comment, user.
3rd table would then obviously be the users info like userid, username, password etc.

Then the ajax query queries the database with something like: "select chat_title, idnumb, comment, name from chat_table, comment_table, user_table where chat_table.id = '35' and userid = column_table.user offset 0 limit 20 order by idnumb desc

This would then fetch the last 20 comments, usernames for the comments, title of the chat.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.