How to show status

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
micknc
Forum Contributor
Posts: 115
Joined: Thu Jan 24, 2008 11:13 pm

How to show status

Post by micknc »

I am not sure if this is even possible but I have written a page that formats and transfers data from one mysql table to another. Is there any script that would help me show the status of this transfer?

The table will have different numbers of rows each time and the user has no idea if it is 20 rows or 20 thousand. Any ideas?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: How to show status

Post by s.dot »

You could print it out to the page.. ;p using mysql_num_rows() to determine how many rows there are

Code: Select all

$i = 0;
$numRows = mysql_num_rows($result);
while (...)
{
    echo $i++ . ' rows out of ' . $numRows . ' transferred<br />';
}
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
micknc
Forum Contributor
Posts: 115
Joined: Thu Jan 24, 2008 11:13 pm

Re: How to show status

Post by micknc »

I thought about using something like that but that is going to output a new line for every loop sequence so it would basically only be useful as long as it was on the screen (30 lines or so).
Instead of looking like this:

0 rows out of 2035 transferred
1 rows out of 2035 transferred
2 rows out of 2035 transferred
3 rows out of 2035 transferred
4 rows out of 2035 transferred
5 rows out of 2035 transferred
6 rows out of 2035 transferred
7 rows out of 2035 transferred
8 rows out of 2035 transferred
9 rows out of 2035 transferred
10 rows out of 2035 transferred
11 rows out of 2035 transferred

I am trying to keep it all in the first line. If I put it in the loop I get the above. Outside of the loop I get nothing till it is all said and done anyway...
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: How to show status

Post by s.dot »

Well, you could limit it.

Code: Select all

$i = 0;
while (...)
{
     if (($i % 100) == 0)
     {
         //echo rows printed
     }
}
That would print every 100 rows.
You cannot echo anything outside of the while loop until the loop is finished.

If the printing gets too long, you could use javascript to scroll to the bottom, if it is that important.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
micknc
Forum Contributor
Posts: 115
Joined: Thu Jan 24, 2008 11:13 pm

Re: How to show status

Post by micknc »

So here is what I have to show the percentage complete based on rows:

Code: Select all

<html>
<head>
<style type="text/css"><!--
 
div {
 margin: 1px;
 height: 20px;
 padding: 1px;
 border: 1px solid #000;
 width: 275px;
 background: #fff;
 color: #000;
 float: left;
 clear: right;
 top: 38px;
 z-index: 9
}
 
.percents {
 background: #FFF;
 border: 1px solid #CCC;
 margin: 1px;
 height: 20px;
 position:absolute;
 width:275px;
 z-index:10;
 left: 10px;
 top: 38px;
 text-align: center;
}
-->
</style>
</head>
<body>
 
<?php
include "../../includes/dbconnect.php";
 
echo str_pad('Loading... ',4096)."<br />\n";
 
$result=mysql_query("select * from inv001");
$numRows = mysql_num_rows($result);
$percentage = 100/$numRows;
$d = $percentage;
$i = $percentage;
while($row=mysql_fetch_assoc($result)){
    $i = $i + $percentage;
    $d = $d + $percentage;
    $iformat = round($i);
    echo '<div class="percents">' . $iformat . '%&nbsp;complete</div>';
 
mysql_query("INSERT STATEMENT") or die(mysql_error());
}
?>
<div class="percents" style="z-index:12">Done.</div>
</body>
</html>
It is adaptation of a progress bar using the flush function but it gets the job done. Let me know if you see anything that can be improved upon.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: How to show status

Post by John Cartwright »

Take a look at a script called BigDump. It takes x amount of queries then resets the page at the correct pointer (using sessions). This also helps reduce the memory load/execution time limitations.

This combined with ajax would probably be most ideal.
Post Reply