PHP + JavScript + Ajax + MySQL Progress Bar
Hello,
I have a few questions on a module that I am trying to implement on my web.
1. Is it possible to create a progress bar that display the progress of the queries? For example, I import a csv file and that file has 1000 rows. The rows will be inserted into a table in a MySQL Database. As the rows are being inserted into the database, the progress will increase on the progress bar.
2. If yes, will I be needing any external extension for it?
3. Will it be server-side or client-side?
I hope that it is possible. Thank you!
Re: PHP + JavScript + Ajax + MySQL Progress Bar
1. Yes.
2. You can write it all yourself, or possibly find frameworks already.
3. Both. You'll need the server-side to process the queries and report back to the client. You'll need the client to display updates from the server.
Re: PHP + JavScript + Ajax + MySQL Progress Bar
Quote:
Originally Posted by
PeejAvery
1. Yes.
2. You can write it all yourself, or possibly find frameworks already.
3. Both. You'll need the server-side to process the queries and report back to the client. You'll need the client to display updates from the server.
Do you have any ideas or solutions for me to solve it? I'm kind of at a lost here right now.
Re: PHP + JavScript + Ajax + MySQL Progress Bar
Run your PHP query file in a hidden <iframe>. Then after each query output JavaScript to tell the parent frame (window) to update an incremental variable that will reflect in some progress update notification. Remember to flush the buffer after each few queries or else there will be no server-side output until after all 1000 queries are done.
Re: PHP + JavScript + Ajax + MySQL Progress Bar
How will I know how many rows are there in a file? Should I make a function to read how many rows are there in the file and store it in a variable and then use it later on?
Do you have any samples or examples that you can show me?
Thanks for your time.
Re: PHP + JavScript + Ajax + MySQL Progress Bar
Just use PHP's file() function which returns an array from a file with line returns as the delimiter. Then you just count the array. Make sure to remove blank lines.
Re: PHP + JavScript + Ajax + MySQL Progress Bar
Sorry for the really late reply. There were more urgent things that I needed to deal with first.
After I get the number of lines through the file() function, how would I be able to know how many lines have been read or queried? Since I am going to query the rows in the file and put them into MySQL database.
Thanks again for your help!
Re: PHP + JavScript + Ajax + MySQL Progress Bar
There are only two ways to iterate an array...both have integers tied to them. Just use that.
PHP Code:
for ($i = 0; $i < count($array); $i++) {...}
PHP Code:
foreach ($array as $i => $row) {...}
Re: PHP + JavScript + Ajax + MySQL Progress Bar
So, I would have to read the data in the file and put them in an array, then I'll have to loop through the array and query them into the database?
But, what if there are a few columns? Each row has a few columns.
Re: PHP + JavScript + Ajax + MySQL Progress Bar
A few columns? So your file isn't rows of queries?
Re: PHP + JavScript + Ajax + MySQL Progress Bar
I think I get it now. This is what I have done:
Code:
$count=0;
$file = fopen("test2.csv", 'r');
while (($line = fgetcsv($file)) !== FALSE) {
$name[$x] = $line[0];
$addresses[$x] = $line[1];
$statuses[$x] = $line[2];
$count++;
}
Is there any other way to do it or maybe a better way?
Re: PHP + JavScript + Ajax + MySQL Progress Bar
Yes! Do what I already told you post #6...
Quote:
Just use PHP's
file() function which returns an array from a file with line returns as the delimiter. Then you just count the array. Make sure to remove blank lines.
Re: PHP + JavScript + Ajax + MySQL Progress Bar
Alright, thanks!
Another thing, how can I make a script that will keep getting a request of how many queries have been done by the server? This is for me to update the progress bar to be shown to the user.
Re: PHP + JavScript + Ajax + MySQL Progress Bar
Once again...look back. This time...post #4.