Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reflecting changes in database without reloading the page in PHP

Tags:

json

ajax

php

mysql

I am building a photo sharing service in php. I am using a lightbox in jquery which will popup when we click 'add' button to add photos. We can upload multiple photos. Also I am using ajax to upload photos so that the page is not reloaded. I want that after I upload photos the same will be automatically loaded in my gallery and the gallery should display new photos without need to refresh the page. The photos will have a particular id for a particular user in the database, so ulitmately the change in the table for the user should be reflected. Now the problem is that I don't have control over the closing button of the lightbox. Therefore I cannot modify it to call any other function so that it performs the query and displays my photos using ajax. I have heard that we can detect changes in the database automatically using JSON, but I have never used JSON and know almost nothing of it. Can anyone illustrate a simple example in php of how can the changes in a mysql table detected using JSON? Is there any other way to achieve it? Please help me.

like image 209
Sanks R Avatar asked Dec 06 '25 04:12

Sanks R


1 Answers

JSON an ideal data-interchange language.JSON is used for fast data interaction only.so you can not do this with out help of DOM request. http://www.json.org/

You can do this with ajax. You make ajax request for every second for latest update.

or

use long polling method like comet

Implement COMET with PHP

EDIT:- gowri:How to make ajax request per second?

use setInterval

setInterval(function(){

//make your ajax call here

},1000);

like image 65
Gowri Avatar answered Dec 07 '25 20:12

Gowri