Updating database information output

Ask about a PHP problem here.
Post Reply
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Updating database information output

Post by Temor »

Hi guys, I'm not really having an issue here, I'm just to lazy to google this.
I have a " chat " ( a very sloppy prototype of a chat, anyway ) and I store all the messages in a MySQL database. The problem with outputting straight from a database in a chat is that the user will have to refresh the page every few seconds to see if someone else left a message. To work around this I used this simple method:
<meta http-equiv='refresh' content='4'>
Problem is, this looks REALLY cheap, and also has tendencies to ruin the experience for a user ( you cant scroll down to read older messages for more than 4 seconds ). So my question is: Are there any methods you could use to " stealth-ily " update the page ( sort of like Facebook is doing with their commenting system, you just see the new comments, not the entire page refreshing which means you can read older comments without being returned to the top of the page all the time ).

Sorry for the wall of text, and thank you in advance :)
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Updating database information output

Post by jacek »

You can use javascript to get the new content and update the page, it can be a bit of a pain to get right but gives a nice result.

Google "AJAX" :D
Image
Tino
Posts: 360
Joined: Thu May 05, 2011 8:55 pm
Location: The Netherlands

Re: Updating database information output

Post by Tino »

Yes. AJAX. jQuery makes this very easy, raw JS takes a bit more code but is still relatively simple.
Please check out my CodeCanyon items.
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: Updating database information output

Post by Temor »

jacek wrote:You can use javascript to get the new content and update the page, it can be a bit of a pain to get right but gives a nice result.

Google "AJAX" :D
I tried reading a little about AJAX. It gave me a giant headache so I promised myself to never even try it. Ever.
I guess I'll have to break that promise now :(

Thanks anyway.

By the way, you should find some ajax-pro's and get them to join this forum, because I will be having a lot of questions :D
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Updating database information output

Post by jacek »

Temor wrote:By the way, you should find some ajax-pro's and get them to join this forum, because I will be having a lot of questions :D
Once you have the basics of how to use it it's really not complicated ;)
Image
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: Updating database information output

Post by Temor »

jacek wrote:
Temor wrote:By the way, you should find some ajax-pro's and get them to join this forum, because I will be having a lot of questions :D
Once you have the basics of how to use it it's really not complicated ;)
Alright. I'll give it a shot :)
Post Reply