Hi I have data to upload to a Mysql database and I need to get the time taken for each row to be inserted so that I can pass that number through to a progress bar. I have alreay tried accomplishing this by determining the number of rows affetced by the insertion then find the percentage of that number which is not the correct manner to do this.

here is the code

$result3=mysql_query("INSERT INTO dest_table.create_info SELECT * from Profusion.source_cdr") or   die(mysql_error());
$progress=mysql_affected_rows();

// Total processes
$total = $progress;
// Loop through process
for($i=1; $i<=$total; $i++){
// Calculate the percentage
$percent = intval($i/$total * 100)."%";
echo $percent;

this actually divides the total number of rows by 1 and multiplies by 100 to get the percentage and this is wrong .

I need the time taken for each row to be inserted and then find the percentage of that.

Your help will be highly appreciated.

Recommended Answers

All 3 Replies

I need the time taken for each row to be inserted and then find the percentage of that.

You can't with the above code. By the time your code gets to the loop, the query has already been successfully completed.

What pritaeas says is (well, what else would you expect) right. To track progress, you'd have to separately select and insert those rows, which would - in this case - probably create an unnecessary delay in your operation.

Member Avatar for diafol

How big is the transfer?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.