I have a script to import phone number from csv file.
After verification, I put all the result on php array $data_rec[]
with this script :
while (($data = fgetcsv($handle, 1000, ";")) !== FALSE)
{
$data_rec[]=''.$data[0].'';
}
I would like after, to putt all the result on my mysql dbb with an insert to and indicate the pourcentage done with progress bar. I searched from couple of hours on internet, but I can't find fast and easy solution.
My script to insert into mysql dbb :
foreach($data_rec as $id => $number)
{
$req=("INSERT INTO contact VALUES('".$idclient."','', '".$numero."','','','','','','','0')");
$doins = mysql_query($req) or die(mysql_error());
}
I found jqueryprogressbar but I can't understand how to install with my script. Do you have an idea ? Thank you very much
Thank you for your help. I readed your links and find (i think) a way for my problem. But it still doesn't work. I see the progress bar but when all the result was insert (at the end). An idea to Help me ?
On my page test.php I have an ajax script.
<script type='text/javascript'>
$(document).ready(function() {
$("#import_2").click(function (event) {
$("#import_2").attr('class', 'vert');
$('div#display_import').empty(); // we empty the div to display the result (in case of old result)
$.ajax({
type: "POST",
url: "testtest.php",
data: "fonction=importok",
success: function(msg){
$('div#display_import').fadeIn(); // Fade in on the result div
$("div#display_import").append(msg); // display the result of the div
}
});
});
});
</script>
And a button on a div to start the import :
<div style="margin:10px 10px 10px 10px;width: 150px; height: 20px;">
<label id="import_2" style="width: 150px; height: 20px;padding-left: 10px; cursor: pointer;" class="">
<span style="vertical-align: 0px; margin-right: 10px;"><img id="img_tous" src="images/icone-bouton-gris.png" width="10" height="10" style="margin-right: 5px;" /> <strong>IMPORT</strong></span>
</label>
</div>
<div id="display_import" class="texte_13">
</div>
On testtest.php I have my php script to import on mysql dbb The $_SESSION['listeok'] countain an array with all my result (around 12 000 "number")
if(isset($_POST['fonction']) and $_POST['fonction']=="importok")
{
// display progress bar
echo '<div id="progress" style="width:500px;border:1px solid #ccc;"></div>';
echo '<div id="information" style="width"></div>';
// Total processes
$data=$_SESSION['listeok'];
$total=10;
// Loop through process
for($i=1; $i<=$total; $i++)
{
// Calculate the percentation
$percent = intval($i/$total * 100)."%";
// Javascript for updating the progress bar and information
echo '<script language="javascript">
document.getElementById("progress").innerHTML="<div style=\"width:'.$percent.';background-color:#ddd;\"> </div>";
document.getElementById("information").innerHTML="'.$i.' row(s) processed.";
</script>';
$req=("INSERT INTO contact VALUES('".$i."','', '".$data[$i]."','','','','','','','0')");
$doins = mysql_query($req) or die(mysql_error());
// 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>';
}