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?
How to show status
Moderator: General Moderators
Re: How to show status
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.
Re: How to show status
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...
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...
Re: How to show status
Well, you could limit it.
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.
Code: Select all
$i = 0;
while (...)
{
if (($i % 100) == 0)
{
//echo rows printed
}
}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.
Re: How to show status
So here is what I have to show the percentage complete based on rows:
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.
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 . '% complete</div>';
mysql_query("INSERT STATEMENT") or die(mysql_error());
}
?>
<div class="percents" style="z-index:12">Done.</div>
</body>
</html>- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: How to show status
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.
This combined with ajax would probably be most ideal.