CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14
  1. #1
    Join Date
    Jul 2011
    Location
    .NET 3.5
    Posts
    40

    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!

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    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.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Jul 2011
    Location
    .NET 3.5
    Posts
    40

    Re: PHP + JavScript + Ajax + MySQL Progress Bar

    Quote Originally Posted by PeejAvery View Post
    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.

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    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.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    Jul 2011
    Location
    .NET 3.5
    Posts
    40

    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.

  6. #6
    Join Date
    May 2002
    Posts
    10,943

    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.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  7. #7
    Join Date
    Jul 2011
    Location
    .NET 3.5
    Posts
    40

    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!

  8. #8
    Join Date
    May 2002
    Posts
    10,943

    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) {...} 
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  9. #9
    Join Date
    Jul 2011
    Location
    .NET 3.5
    Posts
    40

    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.

  10. #10
    Join Date
    May 2002
    Posts
    10,943

    Re: PHP + JavScript + Ajax + MySQL Progress Bar

    A few columns? So your file isn't rows of queries?
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  11. #11
    Join Date
    Jul 2011
    Location
    .NET 3.5
    Posts
    40

    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?

  12. #12
    Join Date
    May 2002
    Posts
    10,943

    Re: PHP + JavScript + Ajax + MySQL Progress Bar

    Yes! Do what I already told you post #6...

    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.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  13. #13
    Join Date
    Jul 2011
    Location
    .NET 3.5
    Posts
    40

    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.

  14. #14
    Join Date
    May 2002
    Posts
    10,943

    Re: PHP + JavScript + Ajax + MySQL Progress Bar

    Once again...look back. This time...post #4.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured