progress bar problem

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.

okay nauticalmac thanks alot, what i really want is to exit from the query exporting code and start reading the progress bar code so that I can get the time taken to do the whole export of the query to the excel file sheet.

The way your code is written, the php will have completed by the time the html below it is run.
1. You need to run your query asynchronously to the web page so the web page can monitor the progress. For example put your code for exporting the query into a separate 'export' script run by an ajax call. After making the call, your web page is running in parallel to the query.
2. On a regular basis make additional ajax calls to a separate 'progress' script that monitors the progress. Your export query script could keep on writing the number of rows to a file and the progress script read the file and return the number to the web page which would update the progress bar. You want to avoid slowing the export down too much, this defeats the purpose. E.g. for a big file, write for every 100 rows.
3. NOTE: your ajax 'export' script can not download the file directly. You will have to do this from your web page. The 'export' script could save the file to disk and when it returns success to the webpage use javescript to navigate to a new page which downloads the saved file.