EasyUI Forum
April 27, 2024, 09:57:35 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Progress Bar corresponding to data updated in backend PHP  (Read 13200 times)
thecyberzone
Full Member
***
Posts: 176



View Profile Email
« on: August 08, 2016, 07:45:33 AM »

I have an Update button in my frontend html. onClick() event of this button calls a PHP file at server end. This PHP script first retrieves approximately 1000 rows from a table1 of Database1. Then using a loop I have to update another Table2 value of another Database2 corresponding to each column3 value of each row of Table1. This procedure requires a lot of time to update as approximately 1+1000 query will be performed. I want a progress Bar in my front end to show the progress indicating number of rows processed in table1. How this can be made?

An early thanks in advance.  Smiley
« Last Edit: August 08, 2016, 07:49:17 AM by thecyberzone » Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #1 on: August 08, 2016, 06:09:07 PM »

You can get the real progress value from your server and call 'setValue' method to set the progressbar. If you are using the $.messager.progress to display the progressbar, please set the 'interval' property to 0.
Code:
$.messager.progress({
title:'Please waiting',
msg:'Loading data...',
interval:0
});

Call this code to set the progress value.
Code:
var bar = $.messager.progress('bar');
bar.progressbar('setValue', value);

When finished, call $.messager.progress('close') to close the progress message window.
Logged
thecyberzone
Full Member
***
Posts: 176



View Profile Email
« Reply #2 on: August 09, 2016, 01:41:07 AM »

I can't understand. When I called backend PHP file how can I update progress bar value in frontend within PHP script ?
Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #3 on: August 09, 2016, 07:59:48 AM »

You can't update the progress bar within your PHP script, instead, you should write a PHP script that can return the real progress value to the browser. The code below shows how to retrieve and update the real progress value from server.
Code:
var update = function(){
$.ajax({
url: ...,
method: 'post',
dataType:'json',
success: function(data){
bar.progressbar('setValue', data.progress);
if (data.progress < 100){
setTimeout(function(){
update();
},1000);
} else {
$.messager.progress('close');
}
}
})
};
update();
Logged
thecyberzone
Full Member
***
Posts: 176



View Profile Email
« Reply #4 on: August 11, 2016, 12:09:21 AM »

Still confused, I understand client-side calling, but how in backend server-side PHP will send the value of 'progress' thru data ? Please give one example of server-side PHP code for sending the value of 'progress'.
Logged
juancitop
Newbie
*
Posts: 22


View Profile Email
« Reply #5 on: August 11, 2016, 06:22:48 AM »

Still confused, I understand client-side calling, but how in backend server-side PHP will send the value of 'progress' thru data ? Please give one example of server-side PHP code for sending the value of 'progress'.

In your process (server side) you can write a file with %. For ex:

Code:
                $totalItems = 1000;
$i=0;
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {


                //YOUR CODE HERE


    //ProgressBar -------------------------------------------------------
    $i++;
    file_put_contents(
        'progress.json',
        json_encode(array('progress'=>round($i/$totalItems*100,0)))
    );
    //ProgressBar -------------------------------------------------------
}

Then in other php script you can read the file and return progress as espected on jarry's update function.

hope this help you and excuse my bad english...
Logged
thecyberzone
Full Member
***
Posts: 176



View Profile Email
« Reply #6 on: August 12, 2016, 12:25:17 AM »

Again another confusion. I have called backend back.php from ajax call, but your example is passing progress value thru progress.json file, so how that value can be retrieve from clientside javascript. Please give javascript calling in client side and corresponding PHP code snippet for sending value of progress.
Logged
thecyberzone
Full Member
***
Posts: 176



View Profile Email
« Reply #7 on: August 12, 2016, 12:28:42 AM »

Is there any method for getting value from session variable in frontend javascript, because it is very easy to store progress value to session variable using PHP at backend.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!