0

I have a large MYSQL / PHP in a while loop report being run and in many cases the report times out due to the large amount of data being calculated.

Is there a way to make have a div displaying "Processing" when the while loops is calculating and if the report is completed , a div "complete" is displayed.

For example: The calculation are not complete because the variable $totals are not displayed. It is only when $Total is a rational value then "Completed" is displayed.

Many Thanks in advance!

<?php
    session_start();
?>
<html>
<body id="dt_example">
<div "Processing">
<?php
    while($noticia = mysql_fetch_array($query)) { // Very long mysql query , query usually times out in this loop. Div "Processing" shown
        $Total +=$subtotal;
    }

    echo "Totals: ".$Total; //when this is executed , the report is succesful and div "Completed " is displayed
    echo "<div Completed>";

?></tbody></table></div>
</body>
</html>

Edited by chineerat

4
Contributors
3
Replies
37
Views
2 Years
Discussion Span
Last Post by bugz313
0

First of all, mysql_* has been depreciated, consider using pdo/mysqli_*
Based on the situation, I will probably using ajax to retrieve the data for time consuming data. Example, I will start with the div with "loading data...", then when data finished loaded using ajax, simply replace the content of that div. If the data context is too large, I will even break the queries into part(example by pages/limit).

0

In addition to everything @lps says, can you have sql do some of the work in calculating the results you need? You show $total which could likely be calculated from a sql query using aggregate functions like SUM(), etc. MySQL is often much better optimized for generating totals than doing it via PHP.

Edited by madCoder: mention 'aggregate' keyword.

0

You should switch from using table to using divs.

When you use a table the browser doesn't show the table until it gets to the </table> tag. If you use divs as soon as one record is parsed from mysql you get it shown on your website.

You can also set_time_limit(0) while you are generating this so it doesn't time out.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.