Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <?
- @apache_setenv('no-gzip', 1);
- @ini_set('zlib.output_compression', 0);
- @ini_set('implicit_flush', 1);
- for ($i = 0; $i < ob_get_level(); $i++) {
- ob_end_flush();
- }
- ob_implicit_flush(1);
- ?>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
- <title>Exemplo INSERT SQL com ProgressBar</title>
- <style type="text/css">
- .all-rounded {
- -webkit-border-radius: 5px;
- -moz-border-radius: 5px;
- border-radius: 5px;
- }
- .spacer {
- display: block;
- }
- #progress-bar {
- width: 300px;
- margin: 0 auto;
- background: #cccccc;
- border: 3px solid #f2f2f2;
- }
- #progress-bar-percentage {
- background: #3063A5;
- padding: 5px 0px;
- color: #FFF;
- font-weight: bold;
- text-align: center;
- }
- </style>
- </head>
- <body>
- <?php
- function progressBar($percentage) {
- print "<div id=\"progress-bar\" class=\"all-rounded\">\n";
- print "<div id=\"progress-bar-percentage\" class=\"all-rounded\" style=\"width: $percentage%\">";
- if ($percentage > 5) {
- print "$percentage%";
- } else {
- print "<div class=\"spacer\"> </div>";
- }
- print "</div></div>";
- }
- $conexao = mysql_connect('host', 'user', 'senha');
- if (!$conexao)
- die("<h1>Falha na conexão com o Banco de Dados!</h1>");
- mysql_select_db('database');
- $dados = array (
- array('registro0','nome0','numero0','endereco0','data0'),
- array('registro1','nome1','numero1','endereco1','data1'),
- array('registro2','nome2','numero2','endereco2','data2'),
- array('registro3','nome3','numero3','endereco3','data3'),
- array('registro4','nome4','numero4','endereco4','data4'),
- array('registro5','nome5','numero5','endereco5','data5'),
- array('registro6','nome6','numero6','endereco6','data6'),
- array('registro7','nome7','numero7','endereco7','data7'),
- array('registro8','nome8','numero8','endereco8','data8'),
- array('registro9','nome9','numero9','endereco9','data9')
- );
- progressBar(0);
- flush();
- $limite = count($dados);
- for ($i = 0; $i < $limite; $i++) {
- $SQL = " INSERT INTO tb_tabela ( cd_registro, no_nome, nr_numero, no_endereco, ";
- $SQL .= " dt_data ) values ";
- $SQL .= " ('". $dados[$i][0] ."', '". $dados[$i][1] ."', '" .$dados[$i][2] ."', ";
- $SQL .= " '". $dados[$i][3] ."', '". $dados[$i][4] ."') ";
- mysql_query($SQL);
- $parcial = $i * 100 / $limite;
- $text = $parcial . "%";
- //Js atualizando a progressbar
- print('<script type="text/javascript">
- if (document.getElementById("progress-bar-percentage")) {
- document.getElementById("progress-bar-percentage").style.width = "'. $parcial .'%";');
- print('document.getElementById("progress-bar-percentage").innerHTML = "'. htmlspecialchars($text) .'";');
- print('} </script>' . "\n");
- flush();
- // sleep(1); /* Delay para simular um processo demorado da progressbar */
- }
- mysql_close();
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement