Как показать индикатор выполнения при загрузке данных таблицы базы данных в лист Excel в PHP?
1. Создайте таблицу базы данных с 6 столбцами, заполните эту таблицу 100 000 строк фиктивных данных. 2. Теперь создайте сценарий PHP, который показывает кнопку «скачать как лист Excel». 3. При нажатии кнопки «Загрузить как лист Excel» эти 100 000 строк данных будут загружены в виде листа Excel. 4. показать индикатор выполнения или количество записей, над которыми работали во время загрузки. После того, как вы напишете код, поделитесь, пожалуйста, кодом и файлом SQL с данными вместе с инструкциями для нас по настройке на нашем локальном хосте для демонстрации.
вы можете использовать кнопку редактирования в своем вопросе.






<?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 = "allbanki_db";
$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 uacct_id,uacct_suid from user_account";
$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 == "" )
{enter code here
$data = "\n(0) Records Found!\n";
}
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=excel_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>
покажите нам, что вы сделали до сих пор.