EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: thecyberzone on August 08, 2016, 07:45:33 AM



Title: Progress Bar corresponding to data updated in backend PHP
Post by: thecyberzone 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.  :)


Title: Re: Progress Bar corresponding to data updated in backend PHP
Post by: jarry 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.


Title: Re: Progress Bar corresponding to data updated in backend PHP
Post by: thecyberzone 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 ?


Title: Re: Progress Bar corresponding to data updated in backend PHP
Post by: jarry 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();


Title: Re: Progress Bar corresponding to data updated in backend PHP
Post by: thecyberzone 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'.


Title: Re: Progress Bar corresponding to data updated in backend PHP
Post by: juancitop 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...


Title: Re: Progress Bar corresponding to data updated in backend PHP
Post by: thecyberzone 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.


Title: Re: Progress Bar corresponding to data updated in backend PHP
Post by: thecyberzone 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.