How do I show "loading" text in PHP while code (like a massive database query) is running?
Asked
Active
Viewed 1,310 times
0
-
1This could be a good place to start: http://stackoverflow.com/questions/1305260/how-to-show-ajax-loading-gif-animation-while-the-page-is-loading – James Sep 01 '11 at 05:05
-
I second that. This looks like a possible duplicate. – Herbert Sep 01 '11 at 05:20
-
that has nothing to do with php... – benck Sep 01 '11 at 05:36
3 Answers
3
You can use AJAX calls.
- Browser shows "loading text"
- Browser processes AJAX request
- When the response would come back, "loading text" disappears and you can do something (for example Redirect to somewhere)

s.webbandit
- 16,332
- 16
- 58
- 82
-
2[AJAX](http://en.wikipedia.org/wiki/Ajax_%28programming%29) is written in javascript – tttony Sep 01 '11 at 05:10
0
Turn off output buffering and output the html and then start your big code.
apache_setenv('no-gzip', 1);
ini_set('zlib.output_compression', 0);
//if you are buffering output currently. Output buffering can be nested.
for ($i = 0; $i < ob_get_level(); $i++) { ob_end_flush(); }
ob_implicit_flush(1);
Safari and IE have a 1k buffer, you probably have to fill that before by outputting blanks for example.

Leif
- 2,143
- 2
- 15
- 26
0
With AJAX you can do it with help of Jquery library.
<html>
<head>
<tittle>Page Tittle</tittle>
<script type="text/javascript" src="/js/jQuery.min.js"></script>
function loadingAjax(div_id) //javascript function
{
$("#"+div_id).html('<img src="ajax-loader.gif"> saving...');
// image displayed when the request started
$.ajax({
type: "POST",
url: "script.php", //php script that will return the database result
data: "name=John&id=28",
success: function(msg){
$("#"+div_id).html(msg); //result displayed after success
}
});
}
</head>
<body>
<a href="#" onclick="loadingAjax('myDiv');">save page</a>
<div id="myDiv"></div>
</body>
Here the image "ajax_loader.gif" will be displayed till your result from the database is ready.
Hope it helps.

Radheshyam Nayak
- 1,038
- 3
- 11
- 20