Good day
I need help incorporating a progress bar into my code, I first needed to export a query from my database but however the time taken for the query to be exported to a xls file should be shown in a form of a progress bar. if i exit from the export code after exporting to an xls file, the progress bar code is not read at all but if i do not exit from the export to xls file code the code tries to output the progress bar into the excel file which it shouldn't do.
Here is the code
<?php connect_local_host();?>
<html lang="en">
this is for the progress bar
<body>
<!-- Progress bar holder -->
<div id="progress" style="width:500px;border:1px solid #ccc;"></div>
<!-- Progress information -->
<div id="information" style="width"></div>
this code here is for exporting the query
<?php
function connect_local_host()
{
$time_start = microtime(true);
$mysqlserver = "localhost";
$user = "root";
$pass = "";
$db = "Profusion";
$link = mysql_connect( "$mysqlserver", $user, $pass );
if ( ! $link )
die( "Couldn't connect to MySQL" );
//print "Successfully connected to server<P>";
mysql_select_db( $db )
or die ( "Couldn't open $db: ".mysql_error() );
//print "Successfully selected database \"$db\"<P>";
$query = "SELECT uniqueid,cdr_id from source_cdr";
$export = mysql_query ($query ) or die ( "Sql error : " . mysql_error( ) );
$fields = mysql_num_fields ( $export );
for ( $i = 0; $i < $fields; $i++ )
{
$header .= mysql_field_name( $export , $i ) . "\t";
}
while( $row = mysql_fetch_row( $export ) )
{
$line = '';
foreach( $row as $value )
{
if ( ( !isset( $value ) ) || ( $value == "" ) )
{
$value = "\t";
}
else
{
$value = str_replace( '"' , '""' , $value );
$value = '"' . $value . '"' . "\t";
}
$line .= $value;
}
$data .= trim( $line ) . "\n";
}
$data = str_replace( "\r" , "" , $data );
if ( $data == "" )
{
$data = "\n(0) Records Found!\n";
}
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=audit_data.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n$data";
//exit();
//}
// progress bar code again
$time_end = microtime(true);
$time = $time_end - $time_start;
$t_t=$time/$fields;
$total = $t_t + 1;// added 1 to verify that the progress bar does work
// Loop through process
for($i=1; $i<=$total; $i++){
// Calculate the percentage
$percent = floatval($i/$total * 100)."%";/
echo round($percent,0);
// Javascript for updating the progress bar and information
echo '<script language="javascript">
document.getElementById("progress").innerHTML="<div style=\"width:'.$percent.';background- color:#ddd;\"> </div>";
</script>';
// This is for the buffer achieve the minimum size in order to flush data
echo str_repeat(' ',1024*64);
// Send output to browser immediately
flush();
// Sleep one second so we can see the delay
sleep(1);
}
// Tell user that the process is completed
echo '<script language="javascript">document.getElementById("information").innerHTML="Process completed"</script>';
echo '<br/>';
echo "Total time taken :"." ".round($time,6) . " s";
}
?>
</body>
</html>
my problem is where the exit command is after the export code is executed I need to incorporate my progress bar on the web browser instead of implementing it in the excel file.
Your help will be highly appreciated.