update page contents from mysql data without reloading

Codes here !

Moderators: macek, egami, gesf

Sergio84
New php-forum User
New php-forum User
Posts: 4
Joined: Sun Apr 15, 2012 4:52 am

update page contents from mysql data without reloading

Postby Sergio84 » Mon May 21, 2012 10:39 am

Hello, is it possible to have a webpage where data is shown from a mysql table that is updated every 5 seconds. but not by reloading the whole page, just by reading the last mysql entry and updating the 4 or 5 values of the page.

I have search a lot in the internet and all i can find is an example using javascript that updates ONLY one value from mysql, but i need several values to be updated.

thanks a lot for your help

User avatar
macek
php-forum Active User
php-forum Active User
Posts: 277
Joined: Wed Aug 25, 2010 10:42 am
Contact:

Re: update page contents from mysql data without reloading

Postby macek » Mon May 21, 2012 10:51 am

It is possible. I reccomend to use jQuery ,..

Sergio84
New php-forum User
New php-forum User
Posts: 4
Joined: Sun Apr 15, 2012 4:52 am

Re: update page contents from mysql data without reloading

Postby Sergio84 » Mon May 21, 2012 11:01 am

macek wrote:It is possible. I reccomend to use jQuery ,..


thank macek. any hint on how to do it? not expecting a full solution but I really have spend hours trying to find something on the net with no luck.

From what i understand i need:

a php file which queries the mysql database. query_mysql.php

a php file with php+jquery that call the query_mysql.php. home.php

any further help is much appreciated. Ill leave a full solution here as soon as i make it work

Novica89
New php-forum User
New php-forum User
Posts: 7
Joined: Fri May 18, 2012 5:34 am

Re: update page contents from mysql data without reloading

Postby Novica89 » Tue May 22, 2012 4:20 am

You need a jQuery file which will use,let's say

$.post ( name_of_the_php_file_where_to_send_data.php,{ variable_name_you_are_sending_to_that_php_file : variable_which_value_it_gets, var2 : value2, var3:value3 },function (data) {
alert (data); //gets the data outputed in the php file and alerts it,just a sample
return false; // if you are querying once some link is clicked,this will assure that you don't redirect to wherever href of that link leads to
);

You don't have to do anything with callback function if you don't want to.

then in the .php file you are sending those variables to,use code similar to this:

if (isset($_POST['variable_name_you_are_sending_to_that_php_file'])) {
$value = $_POST['variable_name_you_are_sending_to_that_php_file'];
if(!empty($value){
$query = "DO SOME MYSQL QUERYING HERE";
$run_query = mysql_query($query);
}
}

More on this (with some examples), http://docs.jquery.com/Post


Return to “mySQL & php coding”

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

cron