Questions about PHP's progress in obtaining data updates

Source: Internet
Author: User
PHP to get Data update progress issues
This post was last edited by aier520 on 2013-12-06 00:59:45

The update.php page is probably as follows:


This page takes a long time to execute and may take a few minutes
$sql = "SELECT * FROM News";
Execute SQL get array $news _arr specific code omitted
$news _count=count ($news _arr)-1; count the number of arrays in order to calculate the progress of the update
Start loop array and update data
foreach ($news _arr as $key = + $value) {
To get data from a database and update it to local data, the code is omitted
$_server[' Wait ']=floor ($key/$news _count*100); Save the update progress in session
}


getdata.php page is the update progress saved in the output session, the code is as follows

echo $_server[' wait '];


The contents of the HTML page are as follows:

Triggers a JS (jquery-written) When this button is clicked

$ (". Bgn,.bgy"). Click (function () {
Url= "http://localhost/update.php";//action page for data update
$.get (URL);//Use AJAX methods to execute the update program
function getwait () {
$.get (
"http://localhost/getdata.php",//Get the progress of data update
function (Redata) {
The problem is here in the above $.get (URL) to perform the update,
If the PHP update script does not complete (that is, the program that update.php this page does not complete),
There will be no data to return, please, friends, how can i solve this problem?
alert (redata);
Here to do the update progress bar processing
},
"Text")
}
SetInterval (getwait, 1000);
})


Share to: more


------Solution--------------------
You have to do a progress bar at the front-end to do a timer timed to submit the data to submit the results submitted once 10% ... No, I'm telling you, that's what it means.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.