Archived

This topic is now archived and is closed to further replies.

The new chat system

This topic is 4950 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, I was wondering how I would go about making a chat system with PHP, MYSQL, and if needed, Javascript. Is this possible? and how would I go abotu doing this? I don't mean code it for me. I would just like a push in the right direction. Thanks. ps: I know how to connect to databases and stuff with MYSQL, I just don't know how to make the content on the page dynamically load without reloading the page every few seconds with javascript. Is this possible? Thanks. [edited by - demonrealms on May 29, 2004 9:02:51 PM]

Share this post


Link to post
Share on other sites

Unfortunately, the only ways I can think of to make a web based chat system involve refreshing the page at regular intervals... The best you could do would probably be to have a constantly refreshing hidden frame check to see whether the main frame actually needs to be updated, and use JavaScript from the hidden frame to refresh the main frame only when there is an update to the chat. If you absolutely didn''t want to refresh pages, I think you''d have to look into making a Java applet.

Share this post


Link to post
Share on other sites
That seems like that would work. I will make an iframe. But how would I retrive the data from the hidden frame? I only have posted information to other frames, but have never been able (or had to for that matter) to tranfers back the results.

Share this post


Link to post
Share on other sites

The easiest way wouldn''t be to load the data with the hidden frame, just use the hidden frame to check whether an update is necessary. Have one php page on the server to redraw the entire chat and load this into the main frame, and have another php page that just checks the database for a new chat message. If there is no new chat message, have it return this JavaScript:


setTimeout("window.location = window.location;", 2000);


If there is a new chat message, have it return the following JavaScript or something similar:


window.parent.frames.MainFrame.location = window.parent.frames.MainFrame.location;
setTimeout("window.location = window.location;", 2000);


This will force the main frame to run the first php page to get the whole chat from the server. Also, you will probably need yet another frame for the user''s input text so that the message they are typing doesn''t get cleared everytime someone else sends a message.

Share this post


Link to post
Share on other sites

Yeah, I don''t see why it wouldn''t work with iframes. Though you might have to change this:

window.parent.frames.MainFrame.location = window.parent.frames.MainFrame.location; 


to this:

window.parent.location = window.parent.location; 


in order to refresh the main frame.

Share this post


Link to post
Share on other sites
Well I''m coming to find it would be better to make a chat system through VC++ with the Win32 intergration. The only problem I''ve found with this whihc I still havn''t ever been able to solve is the fact that I don''t know how to connect ot databases with VC++ 6. I''ve never done it, and I don''t know how to connect to a mysql database. If I figure that out, then arises another problem, how do I connect to a database that is on a server? Thanks in advance.

Share this post


Link to post
Share on other sites
If you have MySQL downloaded and installed on your computer, there is an example of using C code to connect to and query a MySQL server in:

MySQL\examples\libmysqltest
and documentation on how to do this in Chapter 11 of the MySQL reference manual in:

MySQL\Docs\manual.html


However, if you're using a MySQL database as the chat server, it's still going to be necessary for the client to periodically poll the server for new chat messages. If efficiency is your concern, it would be better to have a server program that would push the chat messages to the client, rather than having many clients poll the server for new info.


[edited by - EvilSteve on May 30, 2004 2:48:39 PM]

Share this post


Link to post
Share on other sites