newbie
newbie

Reputation: 11

displaying the result of a database query on change without refreshing the browser

i have a php script which writes data to a file every 5 seconds and have a second php script that opens the file and then queries a database based on the value in that file..

so to display the result of the query i need to run the php script on my browser..since the data in the file keeps changing,so the result of the query will also keep changing,but i can see the new result only when i refresh the browser..

I want a way in which i can see the new result of the query without refreshing the browser.. i am new to this so i hope i explained my problem to my best..waiting for a solution..thanks

Upvotes: 0

Views: 1030

Answers (4)

druveen
druveen

Reputation: 1691

Write a JavaScript function and call it on load of page setInterval for that function so it is called after an interval of time in that function write ajax call to page which executes your query and return the values.

setinterval("test()" ,1000);
function test(){
//ajax call to php page
}

Upvotes: 0

S L
S L

Reputation: 14318

You might wanna look at

How to update content based on user actions [like the facebook wall]

And you do not need to "i have a php script which writes data to a file every 5 seconds and have a second php script that opens the file and then queries a database based on the value in that file.."

Upvotes: 0

Rob Williams
Rob Williams

Reputation: 1470

You'll need to use some AJAX function to retrieve the data, and then Javascript to update the browser. Check out http://api.jquery.com/jQuery.ajax for a good place to start.

Upvotes: 1

sush
sush

Reputation: 6077

this will automatically refresh the page for every 5secs

header( "refresh:5;url=page url link" );

Example :

header( "refresh:5;url=http://localhost/incedx.php" );

Upvotes: 0

Related Questions